をクリックできませんListView
。トースト メッセージが表示されません。アイテムをクリックしても機能しません。
関連コード:
public class MainActivity5 extends ListActivity {
final Context context = this;
private ImageButton homebutton;
JSONArray customers = null;
private ProgressDialog pDialog;
private static String url_search_customer = "http://192.168.1.241/myapp/search.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_RESULT = "result";
private static final String TAG_ID = "customer_id";
private static final String TAG_F_NAME = "customer_fname";
private static final String TAG_C_PHONE = "customer_phone";
private static String phNumber;
private static String curActivity;
private static String ID;
private static TextView tvid;
JSONArray result = null;
myObject myObj = new myObject();
JSONParser jsonParser = new JSONParser();
EditText TextViewName;
EditText TextViewPhone;
private Button buttonNewMember;
private Button buttonSearchAgain;
SessionManager session;
static final ArrayList<HashMap<String, String>> customerList = new ArrayList<HashMap<String, String>>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_list_view);
Intent i = getIntent();
phNumber = i.getStringExtra("phn_no");
customerList.clear();
new SearchCustomer().execute();
ListView lv = this.getListView();
OnItemClickListener listener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long id) {
Toast.makeText(getApplicationContext(), "Long Clicked " , Toast.LENGTH_SHORT).show();
}
};
lv.setOnItemClickListener(listener);
}
class SearchCustomer extends AsyncTask<String, String, String> {
private boolean successFlag;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity5.this);
pDialog.setMessage("Searching Customer..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
String inputPhnNoText = phNumber;
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("phno", inputPhnNoText));
JSONObject json = jsonParser.makeHttpRequest(url_search_customer,
"POST", params);
Log.d("Search Response", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
successFlag = true;
result = json.getJSONArray(TAG_RESULT);
for (int i = 0; i < result.length(); i++) {
JSONObject c = result.getJSONObject(i);
String id = c.getString(TAG_ID);
String fname = c.getString(TAG_F_NAME);
String phoneNumber = c.getString(TAG_C_PHONE);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, id);
map.put(TAG_F_NAME, fname);
map.put(TAG_C_PHONE, phoneNumber);
customerList.add(map);
}
} else if (success == 0) {
successFlag = false;
Intent i = new Intent(getApplicationContext(),
MainActivity3.class);
i.putExtra("norecords",
"No record Found with phone number only ! Try again !!");
startActivity(i);
pDialog.dismiss();
finish();
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return null;
}
protected void onPostExecute(String file_url) {
if (successFlag = true) {
pDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(MainActivity5.this,
customerList, R.layout.activity_main5, new String[] {
TAG_F_NAME, TAG_C_PHONE, TAG_ID }, new int[] {
R.id.TextViewName, R.id.TextViewPhone, R.id.TextViewID });
setListAdapter(adapter);
} else if(successFlag = false) {
}
}
}
}