我想知道它们之间的实际区别......每个应该何时使用,每个应该如何使用,以及哪些情况都有用?
举几个例子并详细解释.
我想点击编辑文字打开日历.之后,我想设置用户从编辑文本中的日历中选择的日期.问题是,只有当我第二次点击EditText然后打开日历时.请帮我解决问题(why calendar don't open for the first time).
EditText XML代码
<EditText
android:id="@+id/dateofBirth"
android:layout_width="290dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:maxLines="1"
android:hint="dd/mm/yyyy" />
Run Code Online (Sandbox Code Playgroud)
活动代码
public void informationPopUp() {
final Dialog dialog= new Dialog(MainActivity.this,R.style.Dialog_Fullscreen);
dialog.setContentView(R.layout.details_dialog);
dateofBirth = (EditText)dialog.findViewById(R.id.dateofBirth);
dialog.show();
myCalendar = Calendar.getInstance();
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};
dateofBirth.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View …Run Code Online (Sandbox Code Playgroud) 我得到这个warning但却无法理解?
Dropping event due to no window focus:
KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=158, metaState=0,
flags=0x8, repeatCount=0, eventTime=1057872, downTime=1057872, deviceId=4,
displayId=0, source=0x101 }
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释一下,这个警告的原因是什么?
我已经看到一些Style属性需要
android前缀,有些不需要它.是什么原因.喜欢
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
为什么我们没有使用android:windowActionBar和android:windowNoTitle
我有兴趣创建一个通用的BaseAdapter,它将应用于任何具有任何list_item的ListView.它将为list_view设置item_row.
public class GenericAdapter extends BaseAdapter
{
Context context;
ArrayList<HashMap<String, String>> list;
LayoutInflater inflater;
public GenericAdapter (Context context, ArrayList<HashMap<String, String>> list)
{
this.context = context;
this.list = list;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount()
{
return list.size();
}
@Override
public Object getItem(int position)
{
return list.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if(view == null)
{
view = inflater.inflate(R.layout.item_of_any_list, …Run Code Online (Sandbox Code Playgroud) 我在Activity C中有三个片段,它们表现为制表符.我必须从一个片段转到一个新的Activity X.现在我想回到Activity X的片段.
我有覆盖onBackPressed但不知道如何从Activity返回fragment/not fragmentActivity.
如果我想回到一个活动到另一个活动我覆盖后退按下并使用意图调用该活动..
我想做这样的事情..这段代码是为了回到以前的活动
@Override
public void onBackPressed()
{
Intent intent = new Intent(CurrentActivity.this,ActivityYouLikeToGo.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢..
我在RelativeLayout中创建了一个可拖动的视图.但它似乎超越了RelativeLayout.
我只想在ViewGroup中创建一个View draggable
这个观点是draggable根据Screen.它可以超越RelativeLayout的界限.我如何限制它在RelativeLayout中保持可拖动.
CustomImageButton
public class ImageButtonCustom extends ImageButton implements View.OnTouchListener{
float dX, dY;
private RelativeLayout rootView;
private ImageButtonCustom imageButtonCustom;
private OnMoveListener onMoveListener;
public ImageButtonCustom(Context context,RelativeLayout rootView){
super(context);
this.rootView = rootView;
init();
}
public ImageButtonCustom(Context context) {
super(context);
init();
}
public ImageButtonCustom(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ImageButtonCustom(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init(){
imageButtonCustom = this;
setImageResource(R.drawable.upper_left);
setBackgroundColor(Color.TRANSPARENT);
setOnTouchListener(this);
/*RelativeLayout.LayoutParams …Run Code Online (Sandbox Code Playgroud) android android-custom-view ontouchlistener android-relativelayout
我已经使用 WindowManager 绘制了一个叠加层。它的宽度和高度
WindowManager.LayoutParams.MATCH_PARENT具有透明背景。
我的视图必须匹配父级和处理圆触摸侦听器并将其余触摸传递到下面的屏幕
我有两个小circle in left and right corner。我让它们在屏幕上可拖动,效果很好。但是当我点击可见的主屏幕按钮时。WindowManager 不允许可见项目可点击。
int LAYOUT_FLAG = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.
LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE;
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,//changed it to full
WindowManager.LayoutParams.MATCH_PARENT,
LAYOUT_FLAG,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
///| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, this flag can make it in touchable.
///WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
PixelFormat.TRANSLUCENT);
mFloatingView = LayoutInflater.from(this).inflate(R.layout.item_circle_dragging, null);
mFloatingView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return false;
}
});
//Add the view to the window
mWindowManager = …Run Code Online (Sandbox Code Playgroud) 我习惯拥有Android背景:
android_layout_width="match_parent" or android_layout_height="match_parent"
Run Code Online (Sandbox Code Playgroud)
如何在iOS上使用xib完成此行为?
编辑
因为它是一个genericAdapter并不简单,我知道添加点击监听器的方法.这样做并不是一个好习惯onCreateViewHolder.所以这就是为什么我需要一个更好的建议
我创建了一个通用适配器RecyclerView在
android.现在我想要一些改进它的建议.我怎么能添加clickListener.
GenericAdapter.java
public abstract class GenericAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private ArrayList<T> items;
private OnRecyclerItemClicked onRecyclerItemClicked;
public abstract RecyclerView.ViewHolder setViewHolder(ViewGroup parent);
public abstract void onBindData(RecyclerView.ViewHolder holder, T val);
public GenericAdapter(Context context, ArrayList<T> items){
this.context = context;
this.items = items;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RecyclerView.ViewHolder holder = setViewHolder(parent);
return holder;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
onBindData(holder,items.get(position));
}
@Override
public int getItemCount() { …Run Code Online (Sandbox Code Playgroud) android onclicklistener android-viewholder android-recyclerview