i want to set button on click in my list
first i will retrieve form data base (MySQL)name-id-number of student
then display it as list with 2 buttons
the problem is how to but on click listener i try lots of example and
i do not know what is the problem i try to do on item click but it is not work
and no error happened
look at delete button
package com.ksu.sms;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class ManageSection extends ListActivity {
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
boolean x =true;
Button delete;
ArrayList<HashMap<String, String>> studentList;
private static String url_all_student = "http://10.0.2.2/SmsPhp/view_student_info.php";
String cl;
private static final String TAG_SUCCESS = "success";
private static final String TAG_student = "student";
private static final String TAG_StudentID = "StudentID";
private static final String TAG_StudentNo = "StudentNo";
private static final String TAG_FullName = "FullName";
private static final String TAG_Avatar="Avatar";
HashMap<String, String> selected_student;
JSONArray student = null;
private TextView mDateDisplay;
private int mYear;
private int mMonth;
private int mDay;
ImageView imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.manage_section);
mDateDisplay = (TextView) findViewById(R.id.day);
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
mDateDisplay.setText(mDay+"-"+mMonth+"-"+mYear);
studentList = new ArrayList<HashMap<String, String>>();
ListView list1 = getListView();
list1.setAdapter(getListAdapter());
list1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
selected_student =(HashMap<String, String>) studentList.get(pos);
delete =(Button)view.findViewById(R.id.DeleteStudent);
cl=selected_student.get(TAG_StudentID);
delete.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
Log.d("id: ",cl);
Toast.makeText(getBaseContext(),cl,Toast.LENGTH_LONG).show();
}
});
}
});
new LoadAllstudent().execute();
}
class LoadAllstudent extends AsyncTask<String, String, String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ManageSection.this);
pDialog.setMessage("Loading student. Please wait...");
pDialog.setIndeterminate(false);
}
@Override
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_all_student, "GET", params);
Log.d("All student : ", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1)
{
student = json.getJSONArray(TAG_student);
for (int i = 0; i < student.length(); i++)
{
JSONObject c = student.getJSONObject(i);
String StudentID = c.getString(TAG_StudentID);
String StudentNo = c.getString(TAG_StudentNo);
String FullName = c.getString(TAG_FullName);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_StudentID, StudentID);
map.put(TAG_StudentNo, StudentNo);
map.put(TAG_FullName, FullName);
studentList.add(map);
}
} else {
x=false;
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
if (x==false)
Toast.makeText(getBaseContext(),"no student" ,Toast.LENGTH_LONG).show();
ListAdapter adapter = new SimpleAdapter(
ManageSection.this, studentList,
R.layout.list_student, new String[] { TAG_StudentID,
TAG_StudentNo,TAG_FullName},
new int[] { R.id.StudentID, R.id.StudentNo,R.id.FullName});
setListAdapter(adapter);
}
}
}
it there is easy way please help me this problem derive me crazy