I'm having issue with my custom listview (CursorAdapter)
When I click btAdd on 2nd item, it's updating the last list item. And also, when I click an item, it doesn't display this
Log.e("Selected", "" + position);
What I wanna do is to update the edittext of the 2nd item or whatever is the selected item.
MainActivity.class
private void initControls(View rootView) {
lv = (ListView) rootView.findViewById(R.id.listView1);
MyTextView tvHeader = (MyTextView) rootView.findViewById(R.id.tvHeader);
DatabaseHelper dbHelper = new DatabaseHelper(getActivity());
DBConnector.dbConnect(dbHelper);
cursor = dbHelper.getAllItems(user);
adapterProd = new CustomAdapter(getActivity(), cursor);
lv.setAdapter(adapterProd);
adapterProd.notifyDataSetChanged();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Log.e("Selected", "" + position);
}
});
if(adapterProd.getCount() < 1) {
tvHeader.setVisibility(View.VISIBLE);
tvHeader.setText(getResources().getString(R.string.no_saved_items));
} else {
tvHeader.setVisibility(View.GONE);
}
}
class CustomAdapter extends CursorAdapter
{
TextView name, price, description;
EditText etQuantity;
ImageButton ibAdd, ibSubtract;
ImageView img;
LayoutInflater inflater;
#SuppressWarnings("deprecation")
public CustomAdapter(Context context, Cursor c) {
super(context, c);
inflater = LayoutInflater.from(context);
}
#Override
public void bindView(final View itemView, Context context, Cursor cursor) {
name = (TextView) itemView.findViewById (R.id.tvName);
price = (TextView) itemView.findViewById(R.id.tvPrice);
description = (TextView) itemView.findViewById(R.id.tvDescription);
etQuantity = (EditText) itemView.findViewById(R.id.etQuantity);
etQuantity.append(String.valueOf(quantity));
etQuantity.setSelection(etQuantity.getText().length());
ibAdd = (ImageButton) itemView.findViewById(R.id.ibAdd);
ibSubtract = (ImageButton) itemView.findViewById(R.id.ibSubtract);
img = (ImageView) itemView.findViewById(R.id.imageView);
checkBox = (CheckBox) itemView.findViewById(R.id.checkBox);
final String selected =
cursor.getString(
cursor.getColumnIndex(Constants.KEY_ID));
checkBox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
//Case 1
Log.e("Selected", "" + selected);
itemView.setPressed(true);
}
else {
//case 2
Log.e("Deselected", "" + selected);
itemView.setPressed(false);
}
}
});
ibAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
quantity++;
etQuantity.setText(String.valueOf(quantity));
}
});
ibSubtract.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
quantity--;
if(quantity < 1) {
quantity = 1;
}
etQuantity.setText(String.valueOf(quantity));
}
});
if(cursor.getString(
cursor.getColumnIndex(Constants.KEY_PRODUCT_NAME)) != null) {
name.setText(cursor.getString(
cursor.getColumnIndex(Constants.KEY_PRODUCT_NAME)));
price.setText(Formatter.formatWithPesoSign(cursor.getString(
cursor.getColumnIndex(
Constants.KEY_PRODUCT_PRICE))));
description.setText(cursor.getString(
cursor.getColumnIndex(Constants.KEY_PRODUCT_NAME)));
} else {
price.setVisibility(View.GONE);
name.setText(cursor.getString(
cursor.getColumnIndex(Constants.KEY_PRODUCT_PARTITION_KEY)));
description.setText(cursor.getString(
cursor.getColumnIndex(Constants.KEY_PRODUCT_ROW_KEY)));
if(ConnectionDetector.hasNetworkConnection(getActivity())) {
GetSavedItemAsyncTask task = new GetSavedItemAsyncTask(
getActivity(), accessToken, sessionKey,
cursor.getString(
cursor.getColumnIndex(Constants.KEY_PRODUCT_PARTITION_KEY)),
cursor.getString(
cursor.getColumnIndex(Constants.KEY_PRODUCT_ROW_KEY)),
cursor.getString(
cursor.getColumnIndex(Constants.KEY_ID)),
user);
task.execute();
}
}
Picasso.with(getActivity())
.load(Constants.displayProductThumbnail(Constants.MERCHANT,
cursor.getString(
cursor.getColumnIndex(Constants.KEY_PRODUCT_ROW_KEY)), "200"))
.placeholder(R.drawable.placeholder)
.into(img);
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return inflater.inflate(R.layout.list_item, parent, false);
}
}
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="5dp"
android:clickable="true"
android:descendantFocusability="beforeDescendants" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:background="#drawable/card_background_selector"
android:descendantFocusability="afterDescendants">
<ImageView
android:layout_marginRight="10dp"
android:scaleType="fitXY"
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView" />
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView"
android:layout_toLeftOf="#+id/checkBox"/>
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:id="#+id/tvPrice"
android:textColor="#color/cadmium_orange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/price"
android:layout_below="#+id/tvDescription"
android:layout_toRightOf="#+id/imageView" />
<TextView
android:id="#+id/tvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/description"
android:layout_below="#+id/tvName"
android:layout_toRightOf="#+id/imageView" />
<LinearLayout
android:id="#+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/tvPrice"
android:layout_toRightOf="#+id/imageView"
android:layout_toEndOf="#+id/imageView" >
<ImageButton
style="#style/My.Button"
android:id="#+id/ibSubtract"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/ic_remove_white_36dp"
android:padding="5dp" />
<EditText
android:background="#fff"
android:id="#+id/etQuantity"
android:layout_width="30dp"
android:layout_height="30dp"
android:focusable="false"
android:gravity="center"
android:inputType="number" />
<ImageButton
style="#style/My.Button"
android:id="#+id/ibAdd"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:src="#drawable/ic_add_white_36dp"
android:padding="5dp" />
</LinearLayout>
<CheckBox
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/checkBox"
android:checked="false" />
</RelativeLayout>
Any ideas? I would gladly appreciate any help. Thanks.
ibAdd Button click always update last row etQuantity TextView because etQuantity is reference to TextView which is return by getView method on last call.
To update clicked row TextView value use setTag/getTag method to get clicked row in onClick of ibAdd and ibSubtract Buttons. like:
ibAdd.setTag(etQuantity);
ibAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView etQuantityView=(TextView)v.getTag();
quantity++;
etQuantityView.setText(String.valueOf(quantity));
}
});
Do same on ibSubtract Button click to show subtracted value
This is improving on ρяσѕρєя K's answer (which had worked for me). This is a better way of using two tags:
ibAdd.setTag(R.id.TAG_ID_1, etQuantity);
ibAdd.setTag(R.id.TAG_ID_2, new Integer(quantity));
ibAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView etQuantityView = (TextView) v.getTag(R.id.TAG_ID_1);
int prevQuantity = (Integer) v.getTag(R.id.TAG_ID_2);
prevQuantity++;
etQuantityView.setText(String.valueOf(prevQuantity));
}
});
NOTE: The ids R.id.TAG_ID_1 and R.id.TAG_ID_2 are required to be defined in the res/values folder as tags.xml. The contents are like this:
<resources>
<item name="TAG_ID_1" type="id"/>
<item name="TAG_ID_2" type="id"/>
</resources>
Related
I am trying to change the text and check box response of the clicked list item but I am not able to do so. As I not able to get the clicked list item.
The fragment is a part of view pager.
Here is my code,
public class ParticipantsFragment extends Fragment {
private ParticipantAdapter mAdapter;
SwipeRefreshLayout refreshLayout;
private String mParticipantId, mEventId, mGender;
ParticipantsAsyncTask task;
public ParticipantsFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mEventId = getArguments().getString(Config.BUNDLE_KEY_EVENT_ID);
mParticipantId = getArguments().getString(Config.BUNDLE_KEY_PARTICIPANT_ID);
mGender = getArguments().getString(Config.BUNDLE_KEY_GENDER);
Log.v("fragh", mEventId + " " + mParticipantId);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.participant_list, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.no_participant);
task = new ParticipantsAsyncTask();
task.execute();
ListView participantListView = (ListView) rootView.findViewById(R.id.participant_list);
refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout_participant_list);
participantListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.v("Clicked Participant",mAdapter.getItem(position).getParticipantName());
EditText notes = (EditText) rootView.findViewById(R.id.participant_list_item_notes);
String text = notes.getText().toString();
Log.v("Participant Text",text);
CheckBox checkBox = (CheckBox) rootView.findViewById(R.id.participant_list_item_checkbox);
String check;
if(checkBox.isChecked())
{
check = "1";
}
else
{
check = "0";
}
}
});
Button submit = (Button) rootView.findViewById(R.id.submit_participant);
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
mAdapter = new ParticipantAdapter(getContext(), new ArrayList<Participant>());
participantListView.setAdapter(mAdapter);
participantListView.setEmptyView(textView);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
task = new ParticipantsAsyncTask();
task.execute();
refreshLayout.setRefreshing(false);
}
});
return rootView;
}
private class ParticipantsAsyncTask extends AsyncTask<Void, Void, List<Participant>> {
private ProgressDialog progress;
#Override
protected void onPreExecute() {
progress = new ProgressDialog(getContext());
progress.setMessage("Gathering Data...");
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progress.setIndeterminate(true);
progress.setCancelable(false);
progress.show();
}
#Override
protected void onPostExecute(List<Participant> data) {
// Clear the adapter of previous participant data
mAdapter.clear();
// If there is a valid list of {#link Event}s, then add them to the adapter's
// data set. This will trigger the ListView to update.
if (data != null && !data.isEmpty()) {
mAdapter.addAll(data);
}
}
#Override
protected List<Participant> doInBackground(Void... params) {
List<Participant> result;
if (!mGender.isEmpty()) {
HashMap<String, String> map = new HashMap<String, String>();
map.put(Config.KEY_EVENT_ID, mEventId);
map.put(Config.KEY_PARTICIPANT_ID, mParticipantId);
map.put(Config.KEY_GENDER, mGender);
result = QueryUtils.extractParticipantData(map, Config.FEVER_GENDER_FILTER_PARTICIPANT_URL);
} else {
HashMap<String, String> map = new HashMap<String, String>();
map.put(Config.KEY_EVENT_ID, mEventId);
map.put(Config.KEY_PARTICIPANT_ID, mParticipantId);
Log.v("law", mEventId + ", " + mParticipantId);
result = QueryUtils.extractParticipantData(map, Config.FEVER_ALL_PARTICIPANT_URL);
}
progress.dismiss();
return result;
}
}
#Override
public void onDestroyView() {
super.onDestroyView();
mAdapter.clear();
}
}
participant_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/no_participant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center_horizontal"
android:text="#string/no_participant_found"
android:textColor="#color/primaryText"
android:textSize="24sp"
android:visibility="gone" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout_participant_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="#+id/participant_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#color/divider"
android:dividerHeight="1dp"
android:descendantFocusability="beforeDescendants"
android:drawSelectorOnTop="true"
android:headerDividersEnabled="true" />
</android.support.v4.widget.SwipeRefreshLayout>
<Button
android:id="#+id/submit_participant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="20sp"
android:background="#color/colorAccent"/>
</LinearLayout>
participant_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="80dp"
android:clickable="true"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:id="#+id/participant_list_item_id"
android:layout_width="0dp"
android:textStyle="bold"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:textSize="20sp"
tools:text="M78" />
<TextView
android:id="#+id/participant_list_item_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_weight="5"
android:textSize="20sp"
android:fontFamily="sans-serif"
tools:text="Billu Barber" />
<EditText
android:id="#+id/participant_list_item_notes"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_weight="6"
android:textSize="12sp"
android:background="#drawable/participant_list_notes"
android:hint="#string/participant_notes"
android:inputType="textMultiLine"
android:scrollbars="none"
android:imeOptions="actionDone"
android:maxLength="50"
android:padding="4dp" />
<CheckBox
android:id="#+id/participant_list_item_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp" />
</LinearLayout>
Found the answer atlast.
Don't use setOnItemClickListener for item click. Use item view click inside adapter method by using setOnClickListener(). Do things in onClick()
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
View listItemView = convertView;
if (listItemView == null)
{
listItemView = LayoutInflater.from(getContext()).inflate(R.layout.participant_list_item, parent, false);
}
listItemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Toast.makeText(mContext, "click item",Toast.LENGTH_LONG).show();
}
});
Participant currentParticipant = getItem(position);
if(currentParticipant.getParticipantGender().equals("F"))
{
TextView idView = (TextView) listItemView.findViewById(R.id.participant_list_item_id);
idView.setTextColor(getColor(mContext, R.color.colorPrimary));
idView.setText(currentParticipant.getParticipantId());
}
else if(currentParticipant.getParticipantGender().equals("M"))
{
TextView idView = (TextView) listItemView.findViewById(R.id.participant_list_item_id);
idView.setTextColor(getColor(mContext, R.color.colorAccent));
idView.setText(currentParticipant.getParticipantId());
}
TextView nameView = (TextView) listItemView.findViewById(R.id.participant_list_item_name);
nameView.setText(currentParticipant.getParticipantName());
final EditText notesView = (EditText) listItemView.findViewById(R.id.participant_list_item_notes);
notesView.setText(currentParticipant.getParticipantNotes());
CheckBox checkedView = (CheckBox) listItemView.findViewById(R.id.participant_list_item_checkbox);
if (currentParticipant.getParticipantCheck().equals("1"))
{
checkedView.setChecked(true);
}
else
{
checkedView.setChecked(false);
}
return listItemView;
}
Remove this from participant_list_item.xml
android:descendantFocusability="blocksDescendants"
Thank you every one for the help.
<CheckBox
android:id="#+id/participant_list_item_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:focusable="false"
android:clickable="false"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp" />
Try to replace your CheckBox and add this two line
android:focusable="false"
android:clickable="false"
Try this should work in participant_list_item.xml and remove from listview
android:descendantFocusability="blocksDescendants"
you have to do it like this
private EditText notes;
private CheckBox checkBox;
and put these above onclick
notes = (EditText) rootView.findViewById(R.id.participant_list_item_notes);
String text = notes.getText().toString();
Log.v("Participant Text",text);
checkBox = (CheckBox) rootView.findViewById(R.id.participant_list_item_checkbox);
edittext and check box are the view in the listview
hope this will help you
android:clickable=true
Make sure that you have added clickable property to true.
In participantslist.xml file:
<ListView
android:id="#+id/participant_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#color/divider"
android:dividerHeight="1dp"
android:descendantFocusability="beforeDescendants"
android:drawSelectorOnTop="true"
android:headerDividersEnabled="true"
android:clickable=true/>
And let me know if this suggestion was wrong?
I have created a custom ListView by extending LinearLayout for every row (Contact) and i need to select the item, but the method "setOnItemClickListener()" not working. I have just put a onItemSelectedListener under and now the method "setOnItemClickListener" select always the first item though i select other row
MainActivity:
public class MainActivity extends AppCompatActivity {
private ListView lvPhone;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lvPhone = (ListView)findViewById(R.id.listPhone);
final List<PhoneBook> listPhoneBook = new ArrayList<PhoneBook>();
listPhoneBook.add(new PhoneBook(BitmapFactory.decodeResource(getResources(),R.drawable.image),"Contact_1","123456789","av1#gmail.com","1"));
listPhoneBook.add(new PhoneBook(BitmapFactory.decodeResource(getResources(),R.drawable.image),"Contact_2","123456789","av2#gmail.com","2"));
listPhoneBook.add(new PhoneBook(BitmapFactory.decodeResource(getResources(),R.drawable.image),"Contact_3","123456789","av3#gmail.com","3"));
final PhoneBookAdapter adapter = new PhoneBookAdapter(this, listPhoneBook);
lvPhone.setAdapter(adapter);
lvPhone.setItemsCanFocus(false);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final Dialog d = new Dialog(MainActivity.this);
d.setTitle("Login");
d.setCancelable(true);
d.setContentView(R.layout.account);
d.show();
Button button_close = (Button) d.findViewById(R.id.DCancel);
button_close.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
d.dismiss();
}
});
Button button_login = (Button) d.findViewById(R.id.DLogin);
button_login.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String mName = new String("Ciao");
String mPhone;
String mEmail;
String mID;
TextView TextName = (TextView) d.findViewById(R.id.DName);
TextView TextPhone = (TextView)d.findViewById(R.id.DPhone);
TextView TextEmail = (TextView)d.findViewById(R.id.DEmail);
TextView TextID = (TextView)d.findViewById(R.id.DID);
mName=TextName.getText().toString();
mPhone=TextPhone.getText().toString();
mEmail=TextEmail.getText().toString();
mID=TextID.getText().toString();
listPhoneBook.add(new PhoneBook(BitmapFactory.decodeResource(getResources(),R.drawable.image),mName,mPhone,mEmail,mID));
lvPhone.setAdapter(adapter);
d.dismiss();
}
});
}
});
lvPhone.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView TextName = (TextView) view.findViewById(R.id.tvName);
TextView TextPhone = (TextView)view.findViewById(R.id.tvPhone);
TextView TextEmail = (TextView)view.findViewById(R.id.tvEmail);
TextView TextID = (TextView)view.findViewById(R.id.tvID);
String tvName = new String(TextName.getText().toString());
String tvPhone = new String(TextPhone.getText().toString());
String tvEmail = new String(TextEmail.getText().toString());
String tvID = new String(TextID.getText().toString());
Toast.makeText(MainActivity.this, tvName, Toast.LENGTH_SHORT).show();
}
});
lvPhone.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
}
PhoneBookAdapter:
public class PhoneBookAdapter extends BaseAdapter{
private Context mContext;
private List<PhoneBook> mListPhoneBook;
public PhoneBookAdapter (Context context, List<PhoneBook> list) {
mContext = context;
mListPhoneBook = list;
}
#Override
public int getCount() {
return mListPhoneBook.size();
}
#Override
public Object getItem(int position) {
return mListPhoneBook.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
PhoneBook entry = mListPhoneBook.get(position);
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(R.layout.phonebook_row,null);
}
ImageView ivAvatar = (ImageView)convertView.findViewById(R.id.imgAvatar);
ivAvatar.setImageBitmap(entry.getmAvatar());
TextView tvName = (TextView)convertView.findViewById(R.id.tvName);
tvName.setText(entry.getmName());
TextView tvPhone = (TextView)convertView.findViewById(R.id.tvPhone);
tvPhone.setText(entry.getmPhone());
TextView tvEmail = (TextView)convertView.findViewById(R.id.tvEmail);
tvEmail.setText(entry.getmEmail());
TextView tvID = (TextView)convertView.findViewById(R.id.tvID);
tvID.setText(entry.getmID());
return convertView;
}
}
`
PhoneBook_row:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true">
<ImageView
android:id="#+id/imgAvatar"
android:layout_width="70dp"
android:layout_height="70dp"
android:scaleType="fitCenter"
android:src="#drawable/image"
android:clickable="true"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clickable="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvName"
android:textStyle="bold"
android:clickable="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvPhone"
android:textStyle="bold"
android:clickable="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvEmail"
android:textStyle="bold"
android:clickable="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvID"
android:textStyle="bold"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
Replace your PhoneBook_row.xml with the one I am putting up here, I have tried this and it worked for me. I have changed all your android:clickable="true" to android:clickable="false". The reason for doing this is, all of your child views consume click and the result is your parent view i.e ListView not getting the click event. Hope this helps.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false">
<ImageView
android:id="#+id/imgAvatar"
android:layout_width="70dp"
android:layout_height="70dp"
android:scaleType="fitCenter"
android:src="#drawable/image"
android:clickable="false"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clickable="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvName"
android:textStyle="bold"
android:clickable="false"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvPhone"
android:textStyle="bold"
android:clickable="false"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvEmail"
android:textStyle="bold"
android:clickable="false"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvID"
android:textStyle="bold"
android:clickable="false"/>
</LinearLayout>
</LinearLayout>
Looks like you are missing the override.
Add an #Override before the function as shown below.
lvPhone.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
Also adding android:clickable = true in the layout file wouldn't be necessary.
You have changed your question , anyway i believe you can now get the item selected listener working. To get the item which is selected you can use the position as below
lvPhone.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
PhoneBook phoneBook = listPhoneBook.get(position);
Toast.makeText(MainActivity.this, phoneBook.getName() , Toast.LENGTH_SHORT).show();
//where getName is a function to get the name in the phonebook class
}
});
I want to change the button of android grid view row item, when I click in the first row, I can change the button (play) to (pause), then when I go to another row, also I can change the play to pause, but I need to change the previous row automatically to pause, because it is now still play.
I have tried the code below but not effect.
Main Grid XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:numColumns="1"
android:horizontalSpacing="16dp"
android:verticalSpacing="16dp"
android:padding="16dp"
android:clipToPadding="false"/>
</RelativeLayout>
Row XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageViewMain"
android:layout_width="120dp"
android:layout_height="150dp"
android:scaleType="fitXY"
android:src="#drawable/img4" />
<TextView
android:id="#+id/textViewMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageViewMain"
android:layout_margin="5dp"
android:layout_toRightOf="#+id/imageViewMain"
android:text="PRİNCESS BİRTHDAY"
android:textColor="#000"
android:textSize="24dp" />
<TextView
android:id="#+id/textViewYazar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#412204"
android:textStyle="bold"
android:textSize="10sp"
android:text="Yazar : "
android:layout_below="#+id/textViewMain"
android:layout_alignLeft="#+id/textViewMain"
android:layout_alignStart="#+id/textViewMain" />
<TextView
android:id="#+id/textViewYazarName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yazar adı"
android:textColor="#412204"
android:textSize="10sp"
android:layout_below="#+id/textViewMain"
android:layout_toRightOf="#+id/textViewYazar"
android:layout_toEndOf="#+id/textViewYazar"
android:layout_marginLeft="26dp"/>
<TextView
android:id="#+id/textViewSeslendiren"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#412204"
android:textStyle="bold"
android:textSize="10sp"
android:text="Seslendiren : "
android:layout_below="#+id/textViewYazar"
android:layout_alignLeft="#+id/textViewMain"
android:layout_alignStart="#+id/textViewMain" />
<TextView
android:id="#+id/textViewSeslendirenName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Seslendiren Adı"
android:textColor="#412204"
android:textSize="10sp"
android:layout_below="#+id/textViewYazarName"
android:layout_toRightOf="#+id/textViewYazar"
android:layout_alignStart="#+id/textViewYazarName"/>
<TextView
android:id="#+id/textViewSizeDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#412204"
android:textStyle="bold"
android:textSize="10sp"
android:text="120 MB / 130 Mins"
android:layout_below="#+id/textViewSeslendirenName"
android:layout_alignLeft="#+id/textViewMain"
android:layout_alignStart="#+id/textViewMain" />
<Button
android:id="#+id/buttonPlay"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_above="#+id/imageViewBottomLine"
android:layout_alignLeft="#+id/textViewMain"
android:background="#drawable/ic_action_play"/>
<ImageView
android:id="#+id/imageViewTL"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/tl_simgesi"
android:layout_alignTop="#+id/textViewPrice"
android:layout_toLeftOf="#+id/textViewPrice"/>
<TextView
android:id="#+id/textViewPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2.70"
android:textColor="#E85404"
android:textSize="18dp"
android:textStyle="bold"
android:layout_marginRight="50dp"
android:layout_marginBottom="10dp"
android:layout_above="#+id/imageViewBottomLine"
android:layout_alignParentRight="true" />
<Button
android:id="#+id/buttonAdd"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/ic_action_basket_dark"
android:layout_above="#+id/imageViewBottomLine"
android:layout_alignParentRight="true"
android:onClick="onAddToCard"/>
<ImageView
android:id="#+id/imageViewBottomLine"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignBottom="#+id/imageViewMain"
android:scaleType="fitXY"
android:src="#drawable/top_line" />
</RelativeLayout>
View Adaptor GetView Code
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
LayoutInflater inflator = activity.getLayoutInflater();
imageLoader = new ImageLoader(activity.getApplicationContext());
if (convertView == null) {
holder = new ViewHolder();
convertView = inflator.inflate(R.layout.gridrow2, null);
holder.imgViewMain = (ImageView) convertView.findViewById(R.id.imageViewMain);
holder.txtViewTitle = (TextView) convertView.findViewById(R.id.textViewMain);
holder.txtViewPrice = (TextView) convertView.findViewById(R.id.textViewPrice);
holder.txtViewCast = (TextView) convertView.findViewById(R.id.textViewSeslendirenName);
holder.txtViewAuthor = (TextView) convertView.findViewById(R.id.textViewYazarName);
holder.txtViewSizeDuration = (TextView) convertView.findViewById(R.id.textViewSizeDuration);
holder.play = (Button) convertView.findViewById(R.id.buttonPlay);
holder.addcart = (Button) convertView.findViewById(R.id.buttonAdd);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
imageLoader.DisplayImage(urlList.get(position), holder.imgViewMain);
if (title.get(position).length() > 30) {
holder.txtViewTitle.setTextSize(20);
}
holder.txtViewTitle.setText(title.get(position));
holder.txtViewPrice.setText(price.get(position).replaceAll(" TL", ""));
holder.txtViewCast.setText(cast.get(position));
holder.txtViewAuthor.setText(author.get(position));
holder.txtViewSizeDuration.setText(size.get(position) + " / " + duration.get(position));
holder.imgViewMain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in = new Intent(activity.getApplicationContext(), SubMenu.class);
in.putExtra("Title", title.get(position));
in.putExtra("Id", id.get(position));
in.putExtra("Author", author.get(position));
in.putExtra("Description", description.get(position));
in.putExtra("Img", urlList.get(position));
in.putExtra("Price", price.get(position));
in.putExtra("Size", size.get(position));
in.putExtra("Duration", duration.get(position));
in.putExtra("Publication", publication.get(position));
in.putExtra("Cast", cast.get(position));
activity.startActivity(in);
}
});
holder.play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (holder.click == 0) {
stopPlayer(v.getContext(), position, previousPosition);
productId = id.get(position);
PlayExecute(v.getContext());
v.setBackground(v.getContext().getResources().getDrawable(R.drawable.ic_action_pause));
holder.click = 1;
previousPosition = position;
} else {
stopPlayer(v.getContext(), position, previousPosition);
v.setBackground(v.getContext().getResources().getDrawable(R.drawable.ic_action_play));
holder.click = 0;
}
}
});
holder.addcart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
v.setBackground(v.getContext().getResources().getDrawable(R.drawable.ic_action_basket));
prfs = PreferenceManager.getDefaultSharedPreferences(activity);
productId = id.get(position);
AddExecute();
}
});
return convertView;
}
StopPlayer and change previous icon
public void stopPlayer(Context c, int current, int previous) {
System.out.println("current : " + current);
System.out.println("previous : " + previous);
if (mp != null && mp.isPlaying()) {
mp.stop();
}
if (current!=previous){
View v= this.getView(previousPosition, null, null);
Button b = (Button) v.findViewById(R.id.buttonPlay);
b.setBackground(c.getResources().getDrawable(R.drawable.ic_action_play));
this.notifyDataSetChanged();
mGridview.refreshDrawableState();
}
}
see the attached image please;
http://postimg.org/image/b3fbpc211/
Instead of doing this
View v= this.getView(previousPosition, null, null);
change your drawable on item click method
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Button b = (Button) view.findViewById(R.id.buttonPlay);
b.setBackground(c.getResources().getDrawable(R.drawable.ic_action_play));
your_adapter.notifyDataSetChanged();
}
});
I think , this will work for you :)
I think of you question as a partial refresh one. We all run into partial refresh problem when dealing with ListView or GridView. As for your case, partial refresh may be like this:
private void refreshPartially(int position){
int firstVisiblePosition = listview.getFirstVisiblePosition();
int lastVisiblePosition = listview.getLastVisiblePosition();
if(position>=firstVisiblePosition && position<=lastVisiblePosition){
View view = listview.getChildAt(position - firstVisiblePosition);
if(view.getTag() instanceof ViewHolder){
ViewHolder vh = (ViewHolder)view.getTag();
//holder.play.setBackgroundResource(resId);//Do something here.
...
}
}
}
I have a listview to which I add rows with 1 imagebutton .. I tried to set the imagebutton the setfocusable false but still not working ..
item_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:descendantFocusability="blocksDescendants"
android:id="#+id/RL_item">
<ImageButton
android:layout_width="200dp"
android:layout_height="fill_parent"
android:id="#+id/imageButton"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/LL_Installed"
android:layout_alignRight="#+id/textView2"
android:layout_alignBottom="#+id/textView"
android:layout_alignParentBottom="true"
android:paddingBottom="#dimen/item_list_left_right"
android:paddingLeft="#dimen/item_list_left_right"
android:focusable="false"
android:focusableInTouchMode="false">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/imageView"
android:background="#drawable/tick"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/list_item_installed"
android:id="#+id/textView3"
android:paddingLeft="6dp"
android:textColor="#ffffff"
style="#style/TextShadow"
android:gravity="center_vertical|fill_vertical"
android:layout_weight="1"
android:layout_width="0dip"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=""
android:id="#+id/textView2"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
style="#style/TextShadow"
android:paddingTop="#dimen/item_list_top"
android:paddingRight="#dimen/item_list_left_right"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
style="#style/TextShadow"
android:layout_toLeftOf="#+id/textView2"
android:paddingLeft="#dimen/item_list_left_right"
android:paddingTop="#dimen/item_list_top"
android:focusable="false"
android:focusableInTouchMode="false"/>
</RelativeLayout>
Item_ListAdapter.java
public class Item_ListAdapter extends BaseAdapter {
private final Activity activity;
private final ArrayList<Item_List> items;
private View vi;
private ImageButton button;
public Item_ListAdapter(Activity activity, ArrayList<Item_List> items) {
this.activity = activity;
this.items = items;
}
#Override
public int getCount() {
return items.size();
}
#Override
public Object getItem(int position) {
return items.get(position);
}
#Override
public long getItemId(int position) {
return items.get(position).getId();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
vi=convertView;
if(convertView == null) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi = inflater.inflate(R.layout.item_list, null);
}
Item_List item = items.get(position);
// Colocar el titulo
// Colocar la fecha
// Colocar el background
// Hacer visible o invisible el layout de instalado
TextView txtTitulo = (TextView) vi.findViewById(R.id.textView);
TextView txtFecha = (TextView) vi.findViewById(R.id.textView2);
LinearLayout LL_Installed = (LinearLayout) vi.findViewById(R.id.LL_Installed);
txtTitulo.setText(item.getTitle());
txtFecha.setText(item.getFecha());
if (item.getInstalled()) {
LL_Installed.setVisibility(View.VISIBLE);
Resources res = vi.getResources();
Bitmap bitmap = BitmapFactory.decodeFile(item.getRutaImagen());
final BitmapDrawable bd = new BitmapDrawable(res, bitmap);
// ----------------------------------
button = (ImageButton) vi.findViewById(R.id.imageButton);
//button.setBackgroundDrawable(bd);
button.setBackground(bd);
button.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
v.getBackground().setColorFilter(Color.parseColor("#B7B2B0"), PorterDuff.Mode.MULTIPLY);
Log.d("aaa","DOWN");
return true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
v.getBackground().clearColorFilter();
v.invalidate();
Log.d("aaa","UP");
return true;
}
return false;
}
});
} else {
LL_Installed.setVisibility(View.INVISIBLE);
}
return vi;
}
This is my 'main' code.. i want detect the press here
ListView lv = (ListView)findViewById(R.id.listView);
Item_ListAdapter adapter = new Item_ListAdapter(ListActivity.this, items);
lv.setAdapter(adapter);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parnet, android.view.View view, int position, long id) {
// Que item ha sido pulsado
Toast.makeText(getApplicationContext(), String.valueOf(position), Toast.LENGTH_SHORT).show();
Log.d("aaa", String.valueOf(position) );
}
});
I believe in order to have BOTH the listView row and the ImageButton clickable, you'll need to set both of these on the ImageButton object:
android:focusable="false"
android:focusableInTouchMode="false"
Give that a shot. I'd also try using an onClickListener on your ImageButton instead of the touchListener.
I have a listview that is a list of events. For each event, I want to have shortcut icons right next to its title for editing and removing. If I tab one of those, it should bring me to another Intent for editing/removing events. How do I achieve this?
My xml has a listview like this:
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
and for each text view:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rowTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
Thank you!
What you need to do is to create a custom Adapter and override the getView method like so:
private class MySecondAdapter extends ArrayAdapter<MiniTask>
{
private ArrayList<MiniTask> list;
public MySecondAdapter(Context context, int textViewResourceId, ArrayList<MiniTask> miniTaskList)
{
super(context, textViewResourceId, miniTaskList);
this.list = new ArrayList<MiniTask>();
this.list.addAll(miniTaskList);
}
public View getView(final int position, View convertView, ViewGroup parent)
{
miniTask = miniTaskList.get(position);
ViewHolder holder = new ViewHolder();
{
LayoutInflater inflator = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflator.inflate(R.layout.check_list_item_new, null);
holder.title = (TextView) convertView.findViewById(R.id.tvItemTitle);
holder.commentsPicturesButton = (ImageView) convertView.findViewById(R.id.iAddCommetOrPicture);
holder.commentsPicturesButton.setTag(position);
holder.commentsPicturesButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent = new Intent(getApplicationContext(), PicturesAndCommentsActivity.class);
intent.putExtra(TasksListActivity.KEY_ID, task.getId());
intent.putExtra("mini_task_text", miniTask.getTitle());
startActivity(intent);
}
});
holder.selected = (CheckBox) convertView.findViewById(R.id.cbCheckListItem);
holder.selected.setTag(position);
holder.selected.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
{
Log.d(TAG, "pressed the checkbox: " + v.getId() + " in position: " + position + " tag: " +v.getTag() +" and item from array: " + miniTaskList.get(position) );
CheckBox checkbox = (CheckBox) v;
miniTaskList.get(position).setSelected(checkbox.isChecked());
numOfCheckedMiniTasks = 0;
for(int i=0;i<miniTaskList.size();i++)
{
miniTask = miniTaskList.get(i);
if(miniTask.isSelected())
{
numOfCheckedMiniTasks ++;
}
}
int percent = (int)(numOfCheckedMiniTasks * 100.0f) / miniTaskList.size();
Log.d(TAG, "the percentage is: " +percent);
tasksRepository.get(tasksRepository.indexOf(task)).setMiniTasksPercentageComplete(percent);
}
}
});
}
holder.title.setText(miniTask.getTitle());
holder.selected.setChecked(miniTask.isSelected());
return convertView;
}
}
In this case I have a checkbox for every row as well, you can ignore it, and the holder is:
static class ViewHolder
{
TextView title;
CheckBox selected;
ImageView commentsPicturesButton;
}
While the XML layout for every row is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/try2"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="#+id/cbCheckListItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/checkbox_checklist_selector"
android:button="#drawable/checkbox_checklist_selector" />
<TextView
android:id="#+id/tvItemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:paddingTop="13dp"
android:text="#string/checklist_item_string"
android:textColor="#color/my_darker_gray" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:paddingTop="6.5dp" >
<ImageView
android:id="#+id/iAddCommetOrPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="#drawable/comment_or_photo_icon"
android:src="#drawable/comment_or_photo_icon" />
</RelativeLayout>
UPDATE:
holder.iParameterWidget.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
currentParameterPosition = position;
}
}
for this you have to create your custom row separately. There are plenty of example you can find. You can see following links to start
http://androidzoo.wordpress.com/2011/10/28/working-with-listview-in-android-customize-listview-add-item-via-a-button-click-and-also-clickable-each-button-in-each-row/
http://www.geekmind.net/2009/11/android-custom-list-item-with-nested.html