リストアイテムをクリックしてクリックした特定の行タイトルを使用して、あるアクティビティから別のアクティビティにKEY_TITLEの値を渡そうとしています。私の場合、この値を渡そうとしています: static final String KEY_TITLE = "title"; OldEventActivityからOldUploadActivityまでですが、常に "index position like: 0, 1" を取得しており、 KEY_TITLEの実際の文字列を取得していません。
OldEventActivity.java:
final ArrayList<HashMap<String, String>> itemsList = new ArrayList<HashMap<String, String>>();
@Override
protected ArrayList<HashMap<String, String>> doInBackground(
String... params) {
HttpClient client = new DefaultHttpClient();
// Perform a GET request for a JSON list
HttpUriRequest request = new HttpGet(URL);
// Get the response that sends back
HttpResponse response = null;
try {
response = client.execute(request);
} catch (ClientProtocolException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Convert this response into a readable string
String jsonString = null;
try {
jsonString = StreamUtils.convertToString(response.getEntity()
.getContent());
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Create a JSON object that we can use from the String
JSONObject json = null;
try {
json = new JSONObject(jsonString);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
JSONArray jsonArray = json.getJSONArray(KEY_CATEGORY);
for (int i = 0; i < jsonArray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject jsonObject = jsonArray.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put(KEY_TITLE, jsonObject.getString(KEY_TITLE));
itemsList.add(map);
}
return itemsList;
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return null;
}
@Override
protected void onPostExecute(ArrayList<HashMap<String, String>> result) {
list = (ListView) findViewById(R.id.listView1);
adapter = new LazyAdapters(OldEventActivity.this, itemsList);
list.setAdapter(adapter);
// Show Item Title in Header
this.progressDialog.dismiss();
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
Intent mViewCartIntent = new Intent(OldEventActivity.this, OldUploadActivity.class);
mViewCartIntent.putExtra("KEY", KEY_TITLE);
startActivity(mViewCartIntent);
}
});
}
}
}
OldUploadActivity.java:
public class OldUploadActivity extends Activity {
public static final String LOG_TAG = "OldUploadActivity";
private ListView lstView;
private Handler handler = new Handler();;
Bundle bundle;
String keytitle;
List <String> ImageList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_uploads);
bundle = getIntent().getExtras();
keytitle = bundle.getString("KEY");
/*** Get Images from SDCard ***/
ImageList = getSD();
Log.d(OldUploadActivity.LOG_TAG, "getSD() :::--- " + ImageList);
// ListView and imageAdapter
lstView = (ListView) findViewById(R.id.listView1);
lstView.setAdapter(new ImageAdapter(this));
}
private List <String> getSD()
{
List <String> it = new ArrayList <String>();
String string = "/mnt/sdcard/Pictures/PicsAngels/";
File f = new File (string + keytitle + "/");
Log.d(OldUploadActivity.LOG_TAG, "KEY_TITLE :::--- " + f);
File[] files = f.listFiles ();
Log.d(OldUploadActivity.LOG_TAG, "getListImages() :::--- " + files);
for (int i = 0; i <files.length; i++)
{
File file = files[i];
Log.d(Upload.LOG_TAG, "i<files.length() :::--- " + i);
Log.d("Count",file.getPath());
it.add (file.getPath());
}
Log.d(Upload.LOG_TAG, "List <String> it :::--- " + it);
return it;
}