listfragment on click into custom list in another fragment
when i click on listfragment particular data that data has to be shown in
custom listview in second fragment.means that clicked item has to be add
in the second fragment. but list view is not appearing..
i took a interface class
public interface FragmentInterface {
public void addData(ArrayList<String> data1,ArrayList<String> data2);
}
listfragment onclick data is added into arraylist//
public void onListItemClick(ListView l, View view, final int position,
long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, view, position, id);
data1 =rowItems.get(position).getDescription();
data2 =rowItems.get(position).getPrice();
desArray.add(data1);
priceArray.add(data2);
if(listener != null){
listener.addData(titleArray,desArray);
System.out.println("lisener"+listener);
}
}
second fragment//
public class MyPlayerFrag extends Fragment {
Context context;
CustomDetailAdapter adapter;
ListView list;
LayoutInflater mInflater;
ArrayList<String> title =new ArrayList<String>();
ArrayList<String> description =new ArrayList<String>();
@Override
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v = inflater.inflate(R.layout.detail, container,false);
list = (ListView)v.findViewById(R.id.listview);
return v;
}
public void detailData(Context applicationContext,ArrayList<String>
data1,ArrayList<String> data2){
this.title =data1;
this.description=data2;
CustomDetailAdapter adapter =new CustomDetailAdapter(context,
title, description);
list.setAdapter(adapter);
here am getting output like in log System.out.println(" title::"+ title);
as[keyboard1,keyboard2]
}
}
public class CustomDetailAdapter extends BaseAdapter {
Context context ;
ArrayList<String> items= null;
ArrayList<String> items1= null;
public CustomDetailAdapter(Context context,ArrayList<String>
items, ArrayList<String> items1) {
this.context =context;
// TODO Auto-generated constructor stub
this.items = items;
this.items1 = items1;
}
/*private view holder class*/
private class ViewHolder {
TextView txtTitle;
TextView txtDesc;
}
public View getView(final int position, View convertView, ViewGroup
parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;
System.out.println("am in getview");
mInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.player, null);
holder = new ViewHolder();
holder.txtTitle = (TextView)
convertView.findViewById(R.id.title);
holder.txtDesc = (TextView)
convertView.findViewById(R.id.desc);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtTitle.setText(items1.get(position));
holder.txtDesc.setText(items.get(position));
return convertView;
}
@Override
public Object getItem(int position) {
return items;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
}
No comments:
Post a Comment