lundi 28 avril 2014

How to disable the list-item which I've just clicked in an listview in android?


Vote count:

0




I've an activity in which I'm showing a list of students(name, roll number) in listview. It's actually to take attendance of students. The user clicks on listview item(which displays his name) and then a dialogbox is opened in which the student enters his password and clicks on "present" button. Whenever the student clicks on "present" button I want to disable the listview item which was just clicked. That means if the student clicks on the same listview item again then he shouldn't be allowed to do so. It would be an immense pleasure if someone helps me out here to disable the list view item.


I'm posting the onclicklistener code I've successfully written so far which does everything I mentioned except the disabling of listview item.



// Adding Items to ListView
ListAdapter adapter = new SimpleAdapter(this, Items,
R.layout.studname_listview, new String[] { "firstname", "lastname", "roll" },
new int[] {R.id.firstname, R.id.lastname, R.id.rollnumber });
listView.setAdapter(adapter);

the main stuff is here
listView.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
{


AlertDialog.Builder alertDialog = new AlertDialog.Builder(DisplayStudentActivity.this);
alertDialog.setTitle("Mark Attendance");
alertDialog.setMessage("Enter your Password");

final EditText input = new EditText(DisplayStudentActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
alertDialog.setView(input);

alertDialog.setIcon(R.drawable.ic_launcher);

alertDialog.setPositiveButton("PRESENT",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub

// some code
if(sTypedPassword.equals(""))
{
Toast.makeText(getApplicationContext(), "Enter your Password", Toast.LENGTH_SHORT).show();
}
else
{
//some code
// here i'm going to say it's correct password and the student is present.
//But after going back from here I want to disable this list view item..
// only the one that was clicked.
// and I want this to happen each time a list view item is clicked and the
//"present" button is clicked
db.closeDB();

}
}
});

alertDialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
dialog.cancel();
}
});

alertDialog.show();
}}});
db.close();}


asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire