I have Two Buttons
along with the text in ListView
. Onclick Listener is not working when i click on Button.
The following is my code:
list_details.xml
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp" />
list_item_details.xml
<TextView
android:id="@+id/try_it"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="tile try" />
<Button
android:id="@+id/download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
/>
ListDetailsActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_details);
productsList = new ArrayList<HashMap<String, String>>();
new LoadAllProducts().execute();
ListView lv = getListView();
Button download = (Button) findViewById(R.id.download);
download.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
TextView try_txt = (TextView) findViewById(R.id.try_it);
String try_text_val = try_txt.getText().toString();
Toast.makeText(getApplicationContext(), try_text_val, Toast.LENGTH_LONG).show();
}
});
}
protected void onPostExecute(String file_url) {
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(
ListDetailsActivity.this, productsList,
R.layout.list_item_details, new String[] { TAG_TRY_IT},
new int[] { R.id.try_it});
// updating listview
setListAdapter(adapter);
}
});
}
}
Many thanks for any help!