两个片段,
问题
我想在TextView上显示数据。怎么可能?
以下是我的代码
First Fragment
alists=new ArrayList<String>();
System.out.println("ARRAYLIST><><><><><"+alists);
GenericUtility.setStringToSharedPrefsForKey("selected_prodname", user_name, getActivity());
GenericUtility.setStringToSharedPrefsForKey("selected_prodprc", dollars+prod_price, getActivity());
btn_add_to_cart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cartincrement();
productnams = GenericUtility.getStringFromSharedPrefsForKey("selected_prodname", getActivity());
System.out.println("Seleced user name=-=-=-=-=-=-==-=" + productnams);
productprc = GenericUtility.getStringFromSharedPrefsForKey("selected_prodprc", getActivity());
System.out.println("Seleced prodprice=-=-=-=-=-=-==-=" + productprc);
alists.add(productnams);
alists.add(productprc);
}
});
relcart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Add_to_cart tf = new Add_to_cart();
Bundle bundle = new Bundle();
bundle.putStringArrayList("prodnam", alists);
// bundle.putString("prodprce", productprc);
tf.setArguments(bundle);
android.support.v4.app.FragmentManager fm = getFragmentManager();
android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.frame_container, tf);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();
}
});
}
第二片段
public class Add_to_cart extends Fragment {
private Button continue_shopping;
private Button checkout;
ListView list;
private TextView _decrease,mBTIncrement,_value;
private CustomListAdapter adapter;
private ArrayList<String> alst;
private String bname;
public Add_to_cart(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.list_view_addtocart, container, false);
alst=new ArrayList<String>();
Bundle bundle = this.getArguments();
alst = bundle.getStringArrayList("prodnam");
System.out.println("NAM--"+alst);
/* for(int i=0;i<alst.size();i++)
{
bname=alst.get(i);
}*/
continue_shopping=(Button)rootView.findViewById(R.id.btn_continueshoppping);
checkout=(Button)rootView.findViewById(R.id.btn_chckout);
adapter = new CustomListAdapter(getActivity(),alst);
list=(ListView)rootView.findViewById(R.id.list_addtocart);
list.setAdapter(adapter);
adapter.notifyDataSetChanged();
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
}
});
continue_shopping.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
HomeFragment tf = new HomeFragment();
android.support.v4.app.FragmentManager fm = getFragmentManager();
android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.frame_container, tf);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();
}
});
checkout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Checkout tf = new Checkout();
android.support.v4.app.FragmentManager fm = getFragmentManager();
android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.frame_container, tf);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();
}
});
return rootView;
}
public class CustomListAdapter extends BaseAdapter {
private Context context;
private ArrayList<String> listData;
//private AQuery aQuery;
String dollars="\u0024";
public CustomListAdapter(Context context,ArrayList<String> listData) {
this.context = context;
this.listData=listData;
// aQuery = new AQuery(this.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;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(getActivity()).inflate(R.layout.list_item_addtocart, null);
holder.txtproname = (TextView) convertView.findViewById(R.id.proname_addtocart);
holder.txtprofilecast = (TextView) convertView.findViewById(R.id.proprice_addtocart);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.txtproname.setText(listData.get(position));
holder.txtprofilecast.setText(dollars+listData.get(position));
//holder.txtprofilecast.setText(dollars+listData.get(position));
// aQuery.id(holder.propic).image(listData.get(position).get(TAG_IMAGE),true,true,0,R.drawable.ic_launcher);
return convertView;
}
class ViewHolder{
ImageView propic;
TextView txtproname;
TextView txtprofilecast;
}