我有ListAdapter有getView();方法。这是方法的代码:
@Override
public View getView(int idx, View view, ViewGroup parent)
{
if(view == null)
{
LayoutInflater vi = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.check, null);
}
return view;
}
这是check.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
<TextView
android:id="@+id/checkedTextView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox1"
android:layout_alignBottom="@+id/checkBox1"
android:layout_toRightOf="@+id/checkBox1"
android:textColor="#615742"
android:textSize="18sp" />
</RelativeLayout>
问题是它只读取复选框。它igonres我的TextView。如果我在xml文件中只写了checkedtextview然后出现文本但是我无法实现复选框。我的代码中有什么问题它忽略了textView并且它只显示了复选框?
答案 0 :(得分:1)
@Override
public View getView(int idx, View view, ViewGroup parent)
{
if(view == null)
{
LayoutInflater vi = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.check, null);
}
TextView tv = (TextView) view.findViewById(R.id.checkedTextView1);
tv.setText("XXXXXXXX");
return view;
}