Get name of the rowItem in listView onClick - java

I am trying to implement a simple listView with onClick functionality. On clicking the item in the listView, I want to show the name of the item in a 'toast message, but I am unable to do that. I have used the method suggested in this link and link but couldn't get the desired result. I have added my code below :
MainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rowItem = new AppList();
final ListView userInstalledApps = (ListView)findViewById(R.id.appListView);
List<AppList> installedApps = getInstalledApps();
CustomAppAdapter installedAppAdapter = new CustomAppAdapter(MainActivity.this, installedApps);
userInstalledApps.setAdapter(installedAppAdapter);
userInstalledApps.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
TextView appName = (TextView)adapterView.findViewById(R.id.list_app_name);
Toast.makeText(getApplicationContext(),
"Clicked "+ adapterView.getItemAtPosition(i),Toast.LENGTH_LONG).show();
}
});
}
CustomAppAdapter.java
public class CustomAppAdapter extends BaseAdapter {
private LayoutInflater layoutInflater;
private List<AppList> listStorage;
Context context;
public CustomAppAdapter(Context context, List<AppList> listStorage) {
layoutInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.listStorage = listStorage;
}
#Override
public int getCount() {
return listStorage.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder listViewHolder;
if(convertView == null){
listViewHolder = new ViewHolder();
convertView = layoutInflater.inflate(R.layout.installed_app_list, parent, false);
listViewHolder.textInListView = (TextView)convertView.findViewById(R.id.list_app_name);
listViewHolder.imageInListView = (ImageView)convertView.findViewById(R.id.app_icon);
convertView.setTag(listViewHolder);
}else{
listViewHolder = (ViewHolder)convertView.getTag();
}
listViewHolder.textInListView.setText(listStorage.get(position).getName());
listViewHolder.imageInListView.setImageDrawable(listStorage.get(position).getIcon());
return convertView;
}
static class ViewHolder{
TextView textInListView;
ImageView imageInListView;
}
}
Below is the screenshot of the listView :
On trying this method:
Toast.makeText(getApplicationContext(),
"Clicked "+ adapterView.getItemAtPosition(i),Toast.LENGTH_LONG).show();
Suppose I clicked on the 2nd item in the listView so I get a toast message as Clicked 2. But I want that it shows me Clicked PhonePe

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rowItem = new AppList();
final ListView userInstalledApps = (ListView)findViewById(R.id.appListView);
List<AppList> installedApps = getInstalledApps();
CustomAppAdapter installedAppAdapter = new CustomAppAdapter(MainActivity.this, installedApps);
userInstalledApps.setAdapter(installedAppAdapter);
userInstalledApps.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
TextView appName = (TextView)adapterView.findViewById(R.id.list_app_name);
Toast.makeText(getApplicationContext(),
"Clicked "+ installedApps.get(i).getName(),Toast.LENGTH_LONG).show();
}
});
}
Try this.

Related

Get value from selected item in AltertDialog listview

I have alter dialog that contains listview with custom adapter populated by some items. Each item has a name and id.
This is item holder:
public class TOperaterHolder {
private String NazivOperatera;
private String IDOperater;
public TOperaterHolder(String nazivOperater, String idOperater) {
this.NazivOperatera = nazivOperater;
this.IDOperater = idOperater;
}
public String getNazivOperatera() {
return NazivOperatera;
}
public void setNazivOperatera(String nazivOperatera) {
NazivOperatera = nazivOperatera;
}
public String getIDOperater() {
return IDOperater;
}
public void setIDOperater(String IDOperater) {
this.IDOperater = IDOperater;
}
}
and this is the custom adapter:
public class CustomAdapterTOperateri extends BaseAdapter {
ArrayList<TOperaterHolder> mData;
Context mContext;
LayoutInflater inflater;
public CustomAdapterTOperateri(ArrayList<TOperaterHolder> data, Context context) {
mData = data;
mContext = context;
inflater = LayoutInflater.from(mContext);
}
public class ViewHolder {
TextView txtNazivTOperater;
}
#Override
public int getCount() {
return mData.size();
}
#Override
public TOperaterHolder getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater mInflater = (LayoutInflater) mContext
.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
view = mInflater.inflate(R.layout.inflate_red, null);
}
TextView tvTitle = (TextView) view.findViewById(R.id.txtNazivTOperater);
View v = (View) view.findViewById(R.id.listViewTOperater);
tvTitle.setText(mData.get(position).getNazivOperatera());
return view;
}
}
This part is placed in activity where I have method to show alter dialog with listview:
private void AlertListItems()
{
AlertDialog.Builder dialog = new AlertDialog.Builder(IzborRazduzivanje.this);
dialog.setTitle("List Title");
View customView = LayoutInflater.from(IzborRazduzivanje.this).inflate(
R.layout.inflate, null, false);
ListView listView = (ListView) customView.findViewById(R.id.listViewTOperater);
ArrayList<TOperaterHolder> itemList = new ArrayList<TOperaterHolder>();
itemList.add(new TOperaterHolder("J", "1"));
itemList.add(new TOperaterHolder("B", "2"));
itemList.add(new TOperaterHolder("C", "3"));
CustomAdapterTOperateri mAdapter = new CustomAdapterTOperateri(itemList, IzborRazduzivanje.this);
listView.setAdapter(mAdapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
dialog.setView(customView);
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
dialog.show();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
TOperaterHolder item = (TOperaterHolder)adapterView.getItemAtPosition(i);
System.out.println("Selected item: " + item.getIDOperater());
}
});
}
When the alert dialog is open I see all three items but when I click on any of them I get an error like
java.lang.NullPointerException: TOperaterHolder.getIDOperater()' on a null object reference
What could be wrong here?
Use
TOperaterHolder item = itemList.get(i);
instead of
TOperaterHolder item = (TOperaterHolder)adapterView.getItemAtPosition(i);
in the onItemClickListener

Can't add Onclick action with button in listview row [duplicate]

This question already has an answer here:
Button inside SimpleCursorAdapter
(1 answer)
Closed 5 years ago.
I'm fresh n funky in android dev. I start learning and got stoped by clickable button in listview!
`public class Test2 extends AppCompatActivity {
private static final String TAG = "Test2";
Button btnEdytuj;
DatabaseHelper myDb;
SimpleCursorAdapter dataAdapter;`
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test2);
myDb = new DatabaseHelper(this);
displayList();
}
private void displayList() {
Cursor cursor = myDb.getAllData();
String from[] = new String[]{myDb.COL_ID, myDb.COL_NAZWA, myDb.COL_LAT, myDb.COL_LON};
int to[] = new int[]{R.id.textView10, R.id.textView1, R.id.textView2, R.id.textView3};
dataAdapter = new SimpleCursorAdapter(this, R.layout.row_item_edit, cursor, from, to, 0);
ListView lv = (ListView) findViewById(R.id.listViewId);
lv.setAdapter(dataAdapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
btnEdytuj = (Button) view.findViewById(R.id.buttonEE);
btnEdytuj.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
// Do something
Intent intent = new Intent(Test2.this,Edytuj.class);
startActivity(intent);`
And my wish is to open new activity from list by intent trigger by pressing a row or a button and passing an id to handle editing.
I have found an error maybe it will helps to figure it out:
android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
in your list adapter do this :
this for get view function :
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.list_note, null);
btnEdytuj = (Button) convertView.findViewById(R.id.buttonEE);
btnEdytuj.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
// Do something
}
});
}
return convertView;
}
this other for bind view:
#Override
public void bindView(View view, Context context, Cursor cursor){
int row_id = cursor.get('_id'); //Your row id (might need to replace)
Button button = (Button) view.findViewById(R.id.buttonEE);
button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
//ADD STUFF HERE you know which row is clicked. and which button
}
});
}
Here you go :
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//Write your code here
}
});
Hope this helps.
You have to put the button onClick method inside Adapter class.
As you have used SimpleCursorAdapter, use button-inside-simplecursoradapter for reference.
Kindly write following code in your activity class.
MainActivity.java
ArrayList<MobileData> searchResults = getMobileData();
final ListView lv1 = (ListView) findViewById(R.id.ListView01);
lv1.setAdapter(new MobileAdapter(this, searchResults));
Add all list item by using adapter class and also add button event in adaptaer class.
MobileAdapter.java
public class MobileAdapter extends BaseAdapter {
private static ArrayList<MobileData> searchArrayList;
private LayoutInflater mInflater;
private Context context;
MobilezonDAO dao;
public MobileAdapter(Context context, ArrayList<MobileData> results) {
this.context = context;
searchArrayList = results;
mInflater = LayoutInflater.from(context);
dao = new MobilezonDAO(this.context);
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.mobile_row_view, null);
holder = new ViewHolder();
holder.mobileImage = (ImageView) convertView.findViewById(R.id.mobileImage);
holder.mobileName = (TextView) convertView.findViewById(R.id.mobileName);
holder.mobilePrice = (TextView) convertView.findViewById(R.id.mobilePrice);
holder.mobileBrand = (TextView) convertView.findViewById(R.id.mobileBrand);
holder.viewDetails = (Button) convertView.findViewById(R.id.viewDetails);
holder.addToCart = (Button) convertView.findViewById(R.id.addToCart);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.mobileImage.setImageBitmap(searchArrayList.get(position).getMobileImage());
holder.mobileName.setText(searchArrayList.get(position).getMobileName());
holder.mobilePrice.setText("Price: $"+searchArrayList.get(position).getMobilePrice());
holder.mobileBrand.setText("Brand: "+searchArrayList.get(position).getMobileBrand());
holder.viewDetails.setBackgroundResource(R.drawable.view_details);
holder.viewDetails.setId(position);
holder.addToCart.setBackgroundResource(R.drawable.addtocart);
holder.viewDetails.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
MobileData mobileData = searchArrayList.get(holder.viewDetails.getId());
Intent intent= new Intent(context, MobileViewDetailsActivity.class);
intent.putExtra("ModelNumber", mobileData.getModelNumber());
context.startActivity(intent);
}
});
holder.addToCart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
MobileData mobileData = searchArrayList.get(holder.viewDetails.getId());
CartData cartData = new CartData();
cartData.setUsername(emailid);
cartData.setModelNumber(mobileData.getModelNumber());
cartData.setPrice(mobileData.getMobilePrice());
cartData.setQuantity("1");
CartData tempCartData = dao.searchParticularCartData(cartData.getUsername(), cartData.getModelNumber());
if(tempCartData!=null && tempCartData.getQuantity()!=null && Integer.valueOf(tempCartData.getQuantity())>0){
Snackbar.make(view, "Selected Mobile already added in your cart.", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}else{
dao.insertCartData(cartData);
Snackbar.make(view, "Mobile has been successfully added in your cart.", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
}
});
return convertView;
}
static class ViewHolder {
ImageView mobileImage;
TextView mobileName;
TextView mobilePrice;
TextView mobileBrand;
Button viewDetails;
Button addToCart;
}
}

how to access the elements of another layout?

I created listView. enter image description here
And my adapter, which has a button, textView.enter image description here
I want to when i click on an button was removed element from the list.
How in the class MainActiviti access to the elements of another layout?
public class AdapterItem extends BaseAdapter {
Context context;
LayoutInflater lInflater;
ArrayList<ItemInList> items;
public AdapterItem(Context context, ArrayList<ItemInList> items){
this.context = context;
this.items = items;
lInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return items.size();
}
#Override
public Object getItem(int position) {
return items.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.item, parent, false);
}
ItemInList itemInList = getItemList(position);
((TextView) view.findViewById(R.id.id_item)).setText(itemInList.id);
((TextView) view.findViewById(R.id.name)).setText(itemInList.name);
((ImageButton) view.findViewById(R.id.imageButton)).setImageResource(itemInList.imageButton);
return view;
}
ItemInList getItemList(int position) {
return ((ItemInList) getItem(position));
}
}
ItemInList.java
public class ItemInList {
String name;
String id;
int imageButton;
boolean deleteChek;
public ItemInList(String name, String id, int imageButton, boolean deleteChek){
this.name = name;
this.id = id;
this.imageButton = imageButton;
this.deleteChek = deleteChek;
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
ArrayList<ItemInList> arrayItemInLists = new ArrayList<ItemInList>();
AdapterItem adapterItem;
ListView listViewl;
Button delete;
Button checkAll;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fillData();
listViewl = (ListView) findViewById(R.id.listView);
delete = (Button) findViewById(R.id.delete_select);
checkAll = (Button) findViewById(R.id.select_all);
adapterItem = new AdapterItem(this, arrayItemInLists);
listViewl.setAdapter(adapterItem);
}
public void fillData() {
for (int i = 1; i <= 20; i++) {
arrayItemInLists.add(new ItemInList("String" + i," " + i, R.drawable.delete,false));
}
}
You need just remove an item from your DATA (in your case - arrayItemInLists) and call notifyDataSetChanged(). In fact you can do that inside an Adapter.
private OnClickListener listener= new OnClickListener() {
#Override
public void onClick(View v) {
int position = ((Integer) v.getTag());
}
};
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.item, parent, false);
}
ItemInList itemInList = getItemList(position);
((TextView) view.findViewById(R.id.id_item)).setText(itemInList.id);
((TextView) view.findViewById(R.id.name)).setText(itemInList.name);
((ImageButton) view.findViewById(R.id.imageButton)).setImageResource(itemInList.imageButton);
((ImageButton) view.findViewById(R.id.imageButton)).setTag(position);
((ImageButton) view.findViewById(R.id.imageButton)).setOnClickListener(listener);
return view;
}

Dynamically adding listitems to baseadapter an android

I want to dynamically add new listitems by pressing a button.but i don't no the right way to do this.
BaseAdapter
public class CompetitionResultListAdapter extends BaseAdapter{
private Activity activity;
private ArrayList<Result> result;
DataManager datamanager;
#Override
public int getCount() {
return result!=null ? result.size() : 0;
}
#Override
public Object getItem(int position) {
return result.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
// inflate the layout
LayoutInflater inflater = activity.getLayoutInflater();
convertView = inflater.inflate(R.layout.list_item_competition_result, parent, false);
}
EditText listItemDate = (EditText) convertView.findViewById(R.id.date);
EditText listItemPlace = (EditText) convertView.findViewById(R.id.place);
EditText listItemComment = (EditText) convertView.findViewById(R.id.comment);
result.get(position).setDate(listItemDate.getText().toString());
result.get(position).setPlace(listItemPlace.getText().toString());
result.get(position).setComment(listItemComment.getText().toString());
return convertView;
}
public void refreshResultList(ArrayList<Result> result){
this.result = result;
notifyDataSetChanged();
}
}
java class
public class AddCompetitionResult extends Fragment {
private CompetitionResultListAdapter competitionResultListAdapter;
private DataManager datamanager;
ArrayList<Result> result;
ListView listView;
private Horse horse;
private Button addResults;
int clickCounter=0;
public AddHorseCompetitionResult(Horse horse) {
this.horse = horse;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.add_horse_competition_result,
null);
addResults = (Button) view.findViewById(R.id.btn_add_competition_result);
listView = (ListView) view.findViewById(R.id.data_list);
// result = datamanager.create(getActivity());
competitionResultListAdapter = new CompetitionResultListAdapter();
View footerView = ((LayoutInflater) getActivity().getSystemService(
Context.LAYOUT_INFLATER_SERVICE)).inflate(
R.layout.competition_result_listview_footer, null, false);
listView.addFooterView(footerView);
listView.setAdapter(competitionResultListAdapter);
addResults.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String resultId = null;
// result.add();
competitionResultListAdapter.notifyDataSetChanged();
}
});
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (competitionResultListAdapter.getCount() == position) {
MainActivity mainActivity = MainActivity.getInstance();
mainActivity.setFragment(new AddHorseDetailedInfo(horse),
"Add horse more info");
// datamanager.createResult(result);
} else {
// ContactGroup cg = (ContactGroup)
// competitionResultListAdapter.getItem(position);
// MainActivity mainActivity = MainActivity.getInstance();
// mainActivity.setFragment(new
// ContactListView(cg.getGroupId()), "contacts");
}
}
});
return view;
}
}
// on button CLick
{
// toast a meesaage here : onClick()
result.add(urObject)// simply put create a object of ur result type and put "" values
// finallly call notifyDataSetChanged on adapter
adapter.notifyDataSetChanged();
}
Tryt to replace your adapter code with this.
public class CompetitionResultListAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<Result> result;
DataManager datamanager;
#Override
public int getCount() {
return result!=null ? result.size() : 0;
}
#Override
public Object getItem(int position) {
return result.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView==null){
holder = new ViewHolder();
convertView = LayoutInflater.from(activity).inflate(R.layout.list_item_competition_result, null, false);
holder.listItemDate = (EditText) convertView.findViewById(R.id.date);
holder.listItemPlace = (EditText) convertView.findViewById(R.id.place);
holder.listItemComment = (EditText) convertView.findViewById(R.id.comment);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
holder.listItemDate = (EditText) convertView.findViewById(R.id.date);
holder.listItemPlace = (EditText) convertView.findViewById(R.id.place);
holder.listItemComment = (EditText) convertView.findViewById(R.id.comment);
result.get(position).setDate(listItemDate.getText().toString());
result.get(position).setPlace(listItemPlace.getText().toString());
result.get(position).setComment(listItemComment.getText().toString());
return convertView;
}
class ViewHolder {
EditText listItemDate;
EditText listItemPlace;
EditText listItemComment;
}
public void refreshResultList(ArrayList<Result> result){
this.result = result;
notifyDataSetChanged();
}
}

how to write code for onitemClickListener for customized listview using BaseAdapter?

here is the code for custom listview using BaseAdapter in android its working fine:
public class CustomListAdapter extends BaseAdapter {
private ArrayList<TaskClass> _listData;
Context _c;
public CustomListAdapter(Context context, ArrayList<TaskClass> listData) {
_listData = listData;
_c = context;
}
#Override
public int getCount() {
return _listData.size();
}
#Override
public Object getItem(int position) {
return _listData.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(int position,View convertView,ViewGroup parent) {
View v = convertView;
if (v == null)
{
LayoutInflater layoutInflator = (LayoutInflater) _c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = layoutInflator.inflate(R.layout.listview_row, null);
}
TextView titleText = (TextView)v.findViewById(R.id.holdTitleText);
TextView catText = (TextView)v.findViewById(R.id.holdCatText);
TextView descText = (TextView)v.findViewById(R.id.holdDescText);
TextView dateText = (TextView)v.findViewById(R.id.holdDateText);
//CheckBox checkBoxForEachItem = (CheckBox)v.findViewById(R.id.)
TaskClass taskClassInstance = _listData.get(position);
titleText.setText(taskClassInstance.getTitle());
catText.setText(taskClassInstance.getTaskCategory());
descText.setText(taskClassInstance.getDescription());
dateText.setText(taskClassInstance.getTaskDate());
return v;
}
}
and in activity i m binding listview with custom adapter :
listViewInstance.setAdapter(new CustomListAdapter(getApplicationContext(),taskClasslistInstance));
where "taskclasslistinstance" is my arraylist conatining data from DB its working fine
now i need to write function for listitemclick so that when user click on any listitem i can get rowid of that listitem record from Database.so after getting rowwid I can delete records from listview and from db and can edit informations
Well, we don't know about your TaskClass, but I expect you want something like this:
listViewInstance.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
TaskClass taskClass = taskClasslistInstance.get(pos);
Log.d(TAG, "Clicked on: " + taskClass)
// Do stuff with taskClass
}});
Here a small example from my project:
list = (ListView) rootView.findViewById(R.id.list);
adapter = new LazyAdapterAlbum(getActivity(), songs);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getActivity(), AlbumActivity.class);
Bundle args = new Bundle();
args.putString(AlbumActivity.ALBUM_NAME, adapter.getItem(position).getName());
i.putExtras(args);
startActivity(i);
}
});
You have to set an onClickListener on your ListView.
you can also set in getView method like below:
public View getView(int position,View convertView,ViewGroup parent) {
View v = convertView;
if (v == null)
{
LayoutInflater layoutInflator = (LayoutInflater) _c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = layoutInflator.inflate(R.layout.listview_row, null);
}
TextView titleText = (TextView)v.findViewById(R.id.holdTitleText);
TextView catText = (TextView)v.findViewById(R.id.holdCatText);
TextView descText = (TextView)v.findViewById(R.id.holdDescText);
TextView dateText = (TextView)v.findViewById(R.id.holdDateText);
//CheckBox checkBoxForEachItem = (CheckBox)v.findViewById(R.id.)
TaskClass taskClassInstance = _listData.get(position);
titleText.setText(taskClassInstance.getTitle());
catText.setText(taskClassInstance.getTaskCategory());
descText.setText(taskClassInstance.getDescription());
dateText.setText(taskClassInstance.getTaskDate());
v.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Perform an action when this list item is clicked
}
});
return v;
}

Categories