I have made a custom layout for my listView, when i test my app without the checkbox inside the layout the listview's items responds to any click, but when i add the checkbox to the layout, the listview's items doesn't respond to any click. I have read so many topics about but i can't find the correct answer. That is a part of my code, listviewrows.xml:
<LinearLayout
...
<TextView android:id="@+id/time_cell"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="12"/>
<TextView android:id="@+id/visco_cell"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="19"/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:checked="false"/>
</LinearLayout>
My activity layout:
<LinearLayout
...
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="11"
android:stackFromBottom="false"
android:transcriptMode="normal"
android:choiceMode="multipleChoice">
</ListView>
</LinearLayout>
And my ListActivity:
public class DataManager extends ListActivity {
SimpleAdapter mresultsListView;
//ListView resultsListView;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
...
readResults();
}
private void readResults(){
ListView resultsListView = getListView();
//resultsListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
resultsListView.setTextFilterEnabled(true);
List <String> readContent = new ArrayList<String>();
String str1;
String str2;
int i,n,j;
File root = Environment.getExternalStorageDirectory();
File dir = new File (root.getAbsolutePath() + "/Viscosity_Results/Results.txt");
IoDisk mydisk = new IoDisk();
readContent = mydisk.readFile(dir, this);
List <String> dataToShow = new ArrayList<String>(readContent);
ArrayList<HashMap<String,String>> myList = new ArrayList<HashMap<String,String>>();
HashMap<String,String> map = new HashMap<String,String>();
//that algortihm to revert the values order
n = readContent.size(); //size of array
for(i=0;i<n;i++){
str1 = readContent.get(n-1-i);
str2 = get_data(str1);
map.put("1", str2);
for(j=0;j<7;j++){
str1 = str1.substring(str1.indexOf(",")+1);
str2 = get_data(str1);
map.put(Integer.toString(j+2), str2);
}
myList.add(map);
map = new HashMap<String,String>();
}
mresultsListView = new SimpleAdapter(this,myList,R.layout.listviewrows,new String[]{"1","2","3","4","5","6","7","8"},
new int[]{R.id.sampid_cell,R.id.userid_cell,R.id.date_cell,R.id.tube_cell,R.id.temp_cell,R.id.ctte_cell,
R.id.time_cell,R.id.visco_cell});
resultsListView.setAdapter(mresultsListView);
}
@Override
protected void onListItemClick(ListView parent, View v,int position,long id){
super.onListItemClick(parent, v, position, id);
Toast.makeText(getBaseContext(), "clicked", Toast.LENGTH_SHORT).show();
My app works correctly the only problem is that i want to click the row item on the listView and the check box needs to be checked automatically, i don't wanna to check just the checkbox manually, even the checkbox mustn't change their state if the user clicked it. please help me to achieve this. Regards.
Aucun commentaire:
Enregistrer un commentaire