私は画像とテキストを連続して表示するリストアクティビティを持っています。アンドロイドでリストのアクティビティをクリックしている間、リストアイテムの静的イメージとテキストを次のアクティビティに送信
イメージは静的で、これらはドロウアブルフォルダに配置されます。
次回のアクティビティで画像やテキストを印刷したいときは、リスト項目をクリックしてください。私は次のアクティビティでテキストビューを正常に送信できます。しかし、次のウィンドウに画像を送るのが難しいことが分かりました。これらは静的であるためです。
誰でもこの問題について私を助けることができます。前もって感謝します。
public class Myimage extends ListActivity {
private LayoutInflater mInflater;
static Vector<RowData> data = new Vector<RowData>();
RowData rd;
static boolean fromCategory = false;
static final String[] title = new String[] {
"One", "Two", "Three "};
private Integer[] img = {
R.drawable.i,R.drawable.im,R.drawable.ima};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mInflater =
(LayoutInflater) getSystemService(
Activity.LAYOUT_INFLATER_SERVICE);
for(int i=0;i<title.length;i++){
try {
rd = new RowData(i,title[i]);
} catch (Exception e) {
e.printStackTrace();
}
data.add(rd);
}
CustomAdapter adapter = new CustomAdapter(this, R.layout.list,
R.id.title, data);
setListAdapter(adapter);
getListView().setTextFilterEnabled(true);
// This is the List Item Click method which i should work to send the image on next activity.
public void onListItemClick(ListView parent, View v, int position,
long id) {
Intent intent = new Intent(this,Second.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
public class RowData {
protected int mId;
protected String mTitle;
RowData(int id,String title){
mId=id;
mTitle = title;
}
public void setTitle(String title) {
this.mTitle = title.trim();
}
public String getTitle() {
return mTitle;
}
public void setId(int i){
this.mId=i;
}
public int getId(){
return mId;
}
@Override
public String toString() {
return mId+" "+mTitle;
}
}
private class CustomAdapter extends ArrayAdapter<RowData> {
public CustomAdapter(Context context, int resource,
int textViewResourceId, List<RowData> objects) {
super(context, resource, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
TextView title = null;
ImageView i11=null;
RowData rowData= getItem(position);
if(null == convertView){
convertView = mInflater.inflate(R.layout.list, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
title = holder.gettitle();
title.setText(rowData.mTitle);
i11=holder.getImage();
i11.setImageResource(img[rowData.mId]);
return convertView;
}
private class ViewHolder {
private View mRow;
private TextView title = null;
private ImageView i11=null;
public ViewHolder(View row) {
mRow = row;
}
public TextView gettitle() {
if(null == title){
title = (TextView) mRow.findViewById(R.id.title);
}
return title;
}
public ImageView getImage() {
if(null == i11){
i11 = (ImageView) mRow.findViewById(R.id.img);
}
return i11;
}
}
} }
に役立つことを願います、int position、 long id){ \t \t意図インテント=新しいインテント(Myimage.this、Second.class); \t \t intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); \t \t RowData rd = data.get(position); \t \t \t \t \t文字列temp = rd.getTitle()+ "splitter" + img [position]; \t \t \t \t \t \t \t \t \t intent.putExtra( "medata"、TEMP)。 \t \t startActivity(インテント); \t \t \t \t \t \t \t} –
及び第二の活動に私が書いた:バンドルエキストラ= getIntent()getExtras();。 \t 文字列tempArr = extras.getString( "medata"); 文字列arr [] = tempArr.split( "splitter"); int aInt = Integer.parseInt(arr [1]); ImageViewイメージ=(ImageView)this.findViewById(R.id.imageView1); image.setImageResource(aInt); \t \t \t TextView tv =(TextView)findViewById(R.id.textView1); tv.setText(arr [0]); \tその作業。 –