嗨,我创建了 android 应用程序 ..它使用 json 解析值。我想将这个 json 值从一个活动传递到另一个活动。我创建了以下代码。
活动1....
public class WaitressActivity extends Activity {
Button btnSearch;
Button btnDisplay;
Button slide;
SimpleSideDrawer slide_me;
Button close;
RelativeLayout window;
ImageView clickWindow;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initActivity();
clickWindow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent init = new Intent(WaitressActivity.this,
TaleActivity.class);
init.putExtras("logo",s);
startActivity(init);
}
});
}
public void jasonParser() {
// Hashmap for ListView
//ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JASONParser jParser = new JASONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
contacts = json.getJSONArray(TAG_RESULT);
logo1=new String[contacts.length()];
name1=new String[contacts.length()];
distance1=new String[contacts.length()];
// looping through All Contacts
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
logoCount=logoCount+1;
// Storing each json item in variable
String latitude = c.getString(TAG_LONGITUDE);
String lognitute = c.getString(TAG_LATITUDE);
storeid = c.getString(TAG_STOREID);
storename = c.getString(TAG_STORENAME);
logo = c.getString(TAG_LOGO);
String city = c.getString(TAG_CITY);
distance = c.getString(TAG_DISTANCE);
String num = c.getString(TAG_NUM);
logo1[i]=logo;
name1[i]=storename;
distance1[i]=distance;
// creating new HashMap
// HashMap<String, String> map = new HashMap<String, String>();
//
// // adding each child node to HashMap key => value
// map.put(TAG_LONGITUDE, latitude);
// map.put(TAG_LATITUDE, lognitute);
// map.put(TAG_STOREID, storeid);
// map.put(TAG_STORENAME, storename);
// map.put(TAG_LOGO, logo);
// map.put(TAG_DISTANCE, distance);
// //
// // // adding HashList to ArrayList
// contactList.add(map);
}
} catch (JSONException e) {
// e.printStackTrace();
}
for(int i=0;i<logoCount;i++){
int distanceIntVlue = Integer.parseInt(distance1[i]);
if (distanceIntVlue < 200 ) {
distanceSecond.setText("Distance meter " + distanceIntVlue);
nameSecond.setText(name1[0]);
imageLoader.DisplayImage(logo1[0], clickWindow);
s=logo1[0];
if(i==1){
int distanceIntVlue1 = Integer.parseInt(distance1[i]);
distanceplace.setText("Distance meter " + distanceIntVlue1);
name.setText(name1[1]);
imageLoaderUp.DisplayImage(logo1[1], logoUp);
}
if(i==2){
imageLoaderUp.DisplayImage(logo1[2], logoUnder);
}
}
}
//tale.showImage(logo);// DownloadAndReadImage dImage = new DownloadAndReadImage();
//
// clickWindow.setImageBitmap(dImage.readBitmapImage(logo));
//
}
public void initActivity() {
btnSearch = (Button) findViewById(R.id.btnsearch);
btnDisplay = (Button) findViewById(R.id.btndisplay);
// Slider=(Button)findViewById(R.id.btnslide);
close = (Button) findViewById(R.id.btnclose);
window = (RelativeLayout) findViewById(R.id.popup);
close.setVisibility(View.INVISIBLE);
window.setVisibility(View.INVISIBLE);
clickWindow = (ImageView) findViewById(R.id.ImageView01);
name = (TextView) findViewById(R.id.name);
distanceplace = (TextView) findViewById(R.id.place);
nameSecond = (TextView) findViewById(R.id.namesecond);
distanceSecond = (TextView) findViewById(R.id.placesecond);
logoUp=(ImageView)findViewById(R.id.imageView1);
logoUnder=(ImageView)findViewById(R.id.ImageView01);
}
}
我的第二个活动是,
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tale);
//
Intent intent = getIntent();
if (null != intent) {
urllogo= intent.getStringExtra("StringName");
}
但问题是,参数“urllogo”总是得到空值。我搜索并尝试了很多方法来做到这一点。但是每次我得到空值..有人可以帮我谢谢..请...