私は学習目的でリストビュー用のシンプルなアンドロイドプログラムを作成しました.テキストと画像でalistviewを取得しました.今私が欲しいのは、リストからアイテムをクリックしたときです.その特定の画像とテキストで次のアクティビティに来るはずです. ..私は以下のように機能していません.同じことを手伝ってください:
主要
package com.example.androidlistview;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
String[] smily = new String[] {"Angry","Basic","Cool","Cry","Err","Evil","Kiss","Laugh","Shame"
,"Toungh","Wink","Wonder"};
int[] pic =new int[]{
R.drawable.ic_action_emo_angry,
R.drawable.ic_action_emo_basic,
R.drawable.ic_action_emo_cool,
R.drawable.ic_action_emo_cry,
R.drawable.ic_action_emo_err,
R.drawable.ic_action_emo_evil,
R.drawable.ic_action_emo_kiss,
R.drawable.ic_action_emo_laugh,
R.drawable.ic_action_emo_shame,
R.drawable.ic_action_emo_tongue,
R.drawable.ic_action_emo_wink,
R.drawable.ic_action_emo_wonder
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<10;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("sml", " " + smily[i]);
hm.put("pic", Integer.toString(pic[i]) );
aList.add(hm);
}
String[] from = { "pic","sml" };
int[] to = { R.id.smily,R.id.txt};
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.list_layout, from, to);
final ListView listView = ( ListView ) findViewById(R.id.listView1);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,Descripsn.class);
String smiley=(String)listView.getSelectedItem();
Bundle b =new Bundle();
intent.putExtra("smily", smiley);
intent.putExtra("image", smily[arg2]);
startActivity(intent);
}
});
}
}
desc.java
package com.example.androidlistview;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.TextView;
public class Descripsn extends Activity {
TextView tv;
ImageView im;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_descripsn);
tv=(TextView)findViewById(R.id.textView1);
im=(ImageView)findViewById(R.id.imagedesc);
Intent i =getIntent();
Bundle b=getIntent().getExtras();
String smily = b.getString("smiley");
int img = b.getInt(smily);
tv.setText(smily);
}
}
ログ
06-21 09:44:38.263: I/Choreographer(4029): Skipped 53 frames! The application may be doing too much work on its main thread.
06-21 09:44:39.523: I/Choreographer(4029): Skipped 58 frames! The application may be doing too much work on its main thread.
06-21 09:44:48.243: I/Choreographer(4029): Skipped 74 frames! The application may be doing too much work on its main thread.
06-21 09:44:48.633: I/Choreographer(4029): Skipped 200 frames! The application may be doing too much work on its main thread.
06-21 09:44:48.853: I/Choreographer(4029): Skipped 46 frames! The application may be doing too much work on its main thread.
06-21 09:44:49.685: I/Choreographer(4029): Skipped 43 frames! The application may be doing too much work on its main thread.
06-21 09:44:54.079: I/Choreographer(4029): Skipped 44 frames! The application may be doing too much work on its main thread.
06-21 09:44:54.733: I/Choreographer(4029): Skipped 46 frames! The application may be doing too much work on its main thread.