我必須將我的價值從一項活動傳遞給另一項活動。 我用Json從數據庫下載數據,並且它可以工作。在其他活動中傳遞數據
我的第一個活動:
public class ListAdapter extends BaseAdapter
{
Context context;
List<cources> valueList;
HashMap<String, String> resultp = new HashMap<String, String>();
public ListAdapter(List<cources> listValue, Context context)
{
this.context = context;
this.valueList = listValue;
}
@Override
public int getCount()
{
return this.valueList.size();
}
@Override
public Object getItem(int position)
{
return this.valueList.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewItem viewItem = null;
if(convertView == null)
{
viewItem = new ViewItem();
LayoutInflater layoutInfiater = (LayoutInflater)this.context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
//LayoutInflater layoutInfiater = LayoutInflater.from(context);
convertView = layoutInfiater.inflate(R.layout.list_adapter_view_test, null);
viewItem.txtTitle = (TextView)convertView.findViewById(R.id.nome_prodotto);
viewItem.txtDescription = (TextView)convertView.findViewById(R.id.descrizione_prodotto);
viewItem.txtPrice = (TextView)convertView.findViewById(R.id.prezzo);
convertView.setTag(viewItem);
}
else
{
viewItem = (ViewItem) convertView.getTag();
}
viewItem.txtPrice.setText(valueList.get(position).prezzo_prodotto);
viewItem.txtTitle.setText(valueList.get(position).nome_prodotto);
viewItem.txtDescription.setText(valueList.get(position).descrizione_prodotto);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// Get the position
Intent intent = new Intent(context, Dettaglio_Prodotto.class);
// Pass all data country
intent.putExtra("nome_prodotto", "test");
// Start SingleItemView Class
context.startActivity(intent);
}
});
return convertView;
}
}
class ViewItem
{
TextView txtTitle;
TextView txtDescription;
TextView txtPrice;
}
我必須要通過的值:
viewItem.txtPrice.setText(valueList.get(position).prezzo_prodotto);
我的第二個活動我的代碼:
Intent i = getIntent();
nome_prodotto = i.getStringExtra("nome_prodotto");
我該怎麼辦呢? 如果我把:
intent.putExtra("nome_prodotto",viewItem.txtTitle.setText(valueList.get(position).nome_prodotto));
我有錯誤: 變量被內部類訪問。需要聲明的最終
問題是什麼? – litelite
如果我把: intent.putExtra(「nome_prodotto」,viewItem.txtTitle.setText(valueList.get(position).nome_prodotto)); 我有錯誤: 在內部類中訪問變量。需要被宣佈爲最終 @litelite –
做錯誤說。將該變量標記爲final。從我所能看到的'viewItem'必須是最終的 – litelite