I have two questions:
If I am using
CheckedTextView
in aListView
and my class only extendsActivity
(instead ofListActivity
), since I have another button at the bottom below myListView
, what event should I listen on, when a checkbox is selected in theCheckedTextView
?If I extend my class to use
ListActivity
, I can useonListItemClick
event, right? How can I add a new button to this type of layout?
Here is my code..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
m_versionText=(TextView)findViewById(R.id.versionText);
m_versionText.setText("Android Version is:" + Build.VERSION.RELEASE);
m_btnAllCalendars = (Button)findViewById(R.id.btn_allCalendars);
m_btnAllCalendars.setOnClickListener(mCalendarListener);
m_calendarList=(ListView)findViewById(R.id.calList);
//populateList uses simplecursoradapter to add items to the listview..(this part is working)
populateList();
m_calCheckText = (CheckedTextView)findViewById(R.id.calTextView);
m_calCheckText.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
if (((CheckedTextView)v).isChecked())
{
Log.d(TAG,"i am inside ...its checked");
}
}
});
private void populateList(){
Log.d(TAG,"inside populateList");
Cursor cursor = getAllCalendars();
startManagingCursor(cursor);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.cal_list,cursor,new String[]{"displayName"},new int []{R.id.calTextView});
//m_calendarList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
m_calendarList.setAdapter(adapter);
}
}
UPDATE:::
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.cal_list,cursor,new String[]{"displayName"},new int []{R.id.calTextView});
m_calendarList=getListView();
m_calendarList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
m_calendarList.setAdapter(adapter);
m_calendarList.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view,int position,long id)
{
Log.d(TAG,"I am inside onItemClick and position is:"+String.valueOf(position));
CheckedTextView ctv = (CheckedTextView)view;
the below code didnt work too
//CheckedTextView ctv = (CheckedTextView)view.findViewById(R.layout.cal_list);
ctv.setChecked(!ctv.isChecked());
}
});
You could try this:
EDIT: