かなり初心者なので、お手柔らかに。私は 2 つの listview parallel を持っています。ここでは、彼がチェックできる listViewSelectFile のみです。問題は、このリストビューからアイテムをチェックしたときです!!! 例:リストビューから最初のアイテムを選択すると、リストビューからスクロールを移動するまで次のアイテムはチェックされません。1 つのページで最大 9 項目が表示され (最初の項目がチェックされ、次の 8 項目がチェックされていない)、10 項目がチェックされ、次の 8 項目がチェックされていない場合、項目 19 がチェックされ、これまでのところ 1 つです。私はテストし、電話を水平にしましたが、それは同じ問題です.スクロールを次のアイテム(CheckTextView ID)に移動すると、彼はid 0 を与え、彼は私の CheckTextView ID を乗算します. どうすればこれを解決できますか? 例はありますか?ありがとうございました !!!!!あなたがしない場合
PopulateListView();
PopulateListView() にあるボットのコード全体:
adapterImageFileName = new ItemsAdapter(
screen3_select_from_lists.this, mImageFilenames);
listViewSelectFile.setAdapter(adapterImageFileName);
listViewSelectFile
.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
// TODO Auto-generated method stub
// When clicked, show a toast with the TextView text
try {
LinearLayout item=(LinearLayout) view;
CheckedTextView tv = (CheckedTextView)item.findViewById(R.id.textView1);
toggle(tv);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
e.getMessage(), Toast.LENGTH_LONG)
.show();
}
}
});
トグル機能 :
public void toggle(CheckedTextView v) {
if (v.isChecked()) {
v.setChecked(false);
} else {
v.setChecked(true);
}
}
MyAdapter :
private class ItemsAdapter extends BaseAdapter {
String[] items;
public ItemsAdapter(Context context, String[] mImageFilenames) {
// TODO Auto-generated constructor stub
this.items = mImageFilenames;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return items.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_view_rows, null);
}
CheckedTextView post = (CheckedTextView)v
.findViewById(R.id.textView1);
post.setText(items[position]);
return v;
}
}
そして私のxml、2つの並列リストビュー:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false" >
<ListView
android:id="@+id/listviewSelectStudents"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:choiceMode="multipleChoice"
>
</ListView>
<ListView
android:id="@+id/listviewSelectFiles"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:choiceMode="multipleChoice">
</ListView>
</LinearLayout>
list_view_rows.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<CheckedTextView
android:id="@+id/textView1"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:onClick="toggle" />
</LinearLayout>