小编jua*_*uan的帖子

带有 CheckBox 的 Android 自定义适配器:setOnClickListener 或 setOnCheckedChangeListener

我有一个自定义适配器,布局中有一个复选框。我可以在 CheckBox 上使用 setOnClickListener 而不出现问题吗?还是最好使用 setOnCheckedChangeListener?

代码:

public class MyAdapter extends ArrayAdapter<Object> {
private Context context;
private LayoutInflater mInflater;
private boolean[] selected;

public MyAdaptader(Context context, List<Object> list) {
    super(context, 0, list);
    this.context = context;
    mInflater = LayoutInflater.from(context);
    selected = new boolean[list.size()];
}

private OnClickListener pressed= new OnClickListener() {
    @Override
    public void onClick(View v) {
        if (((CheckBox) v).isChecked())
            selected[(Integer)v.getTag()] = true;
        else
            selected[(Integer)v.getTag()] = false;
    }
};

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (convertView == …
Run Code Online (Sandbox Code Playgroud)

checkbox android android-arrayadapter

5
推荐指数
1
解决办法
4576
查看次数

Android 片段生命周期 onStop、onDestroyView、onDestroy 和 onDetach

Android 文档谈到 onStop 和 onDestroy 在某些情况下无法调用,但我没有发现任何与片段相同的内容。是否始终调用 onPause、onStop、onDestroyView、on Destroy 和 onDetach?仅在暂停时?

lifecycle android fragment

5
推荐指数
1
解决办法
1万
查看次数

Android RelativeLayout和子元素,layout_width ="match_parent"

当我在同一个"行"有两个视图时,Android如何计算视图的大小,一个宽度="fill_parent"?

例:

<RelativeLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_height="fill_parent"  
    android:layout_width="fill_parent">  
    <EditText  
        android:id="@+id/EditText01"  
        android:hint="Enter some text..."  
        android:layout_alignParentLeft="true"  
        android:layout_width="match_parent"  
        android:layout_toLeftOf="@+id/Button01"  
        android:layout_height="wrap_content"></EditText>  
    <Button  
        android:id="@+id/Button01"  
        android:text="Press Here!"  
        android:layout_width="wrap_content"  
        android:layout_alignParentRight="true"  
        android:layout_height="wrap_content"></Button>  
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

此代码为EditText提供所有可用空间,并在其右侧显示按钮.但是,通过此更改,EditText将填充所有宽度,按钮不在屏幕上:

<RelativeLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_height="fill_parent"  
    android:layout_width="fill_parent">  
    <EditText  
        android:id="@+id/EditText01"  
        android:hint="Enter some text..."  
        android:layout_alignParentLeft="true"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content"></EditText>  
    <Button  
        android:id="@+id/Button01"  
        android:text="Press Here!"  
        android:layout_width="wrap_content"  
    android:layout_toRightOf="@+id/EditText01"
        android:layout_height="wrap_content"></Button>  
</RelativeLayout
Run Code Online (Sandbox Code Playgroud)

android parent match width relativelayout

4
推荐指数
1
解决办法
3856
查看次数

Android 日志,详细是什么意思?

根据关于 Log.e、Log.v、... 的 Android 文档:“详细程度从最少到最多的顺序是 ERROR、WARN、INFO、DEBUG、VERBOSE。除非在开发期间,否则不应将 Verbose 编译到应用程序中”

我的问题是,冗长是什么意思?因为如果我使用 Log.v("TAG","STRING"); 或 Log.e("TAG","STRING"); 我看到同样的信息。

logging android verbosity

3
推荐指数
1
解决办法
1万
查看次数