I have a custom listview in which one textview and one checked box is in each row.
When I click the ckeckbox, I want to add the value from TextView to database and to display a Toast message in the view. The database insertion is working fine. But the application is stopping suddently, and the Toast message is not shown in the view.
public class Favourites extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_list);
ListView listitems = (ListView) findViewById(R.id.ListView_01);
listitems.setAdapter(new EfficientAdapter(this));
}
private static class EfficientAdapter extends BaseAdapter
{
//imp
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
int itemId=SubListIdList.get(position);
TextView text = (TextView) convertView.findViewById(R.id.TextView_02);
CheckBox star = (CheckBox) convertView.findViewById(R.id.star);
star.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)
{
Favourites f=new Favourites();
query="UPDATE "+SUB_TABLE_NAME+" SET FavoriteIndicator='Y' WHERE SubListID="+itemId;
db.execSQL(query);
Toast.makeText(f, "Insertion successfull!", 1).show();
}
}
}
}
}
}
Please help me…. Thank you…
Give the
Toastnotification your main activitiy’s context to display it. I’m not quite sure why you are instantiating your activity again in theonCheckedChanged()method but I guess you were trying to pass yourToasta context with that. Try it this way.And please don’t set your
Toastdisplay time to one millisecond that won’t help you. The time parameters is set in milliseconds.