• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps JSON send string value

shien

Lurker
Hi i am trying to make view that shows only your name but after you click it it shows email and gender. This data was put in JSON file. But now it shows everything and after clicking it also shows everything. Any ideas how to change it?


Code:
ArrayList<HashMap<String,String>> contactList = new ArrayList<HashMap<String,String>>();
        
        JSONParser jParser = new JSONParser();
        JSONObject json = jParser.getJSONFromUrl(url);
        try{
        	contacts = json.getJSONArray(TAG_CONTACTS);
        	for(int i = 0; i < contacts.length(); i++)
        	{
        		JSONObject c = contacts.getJSONObject(i);
        		
        		String id = c.getString(TAG_ID);
        		String vardpav = c.getString(TAG_NAME);
        		String email = c.getString(TAG_EMAIL);
        		String lytis = c.getString(TAG_GENDER);
        		String nuoroda = c.getString(TAG_LINK);
        		
        		HashMap<String,String> map = new HashMap<String, String>();
        		
        		map.put(TAG_ID, id);
        		map.put(TAG_NAME, vardpav);
        		map.put(TAG_EMAIL, email);
        		map.put(TAG_GENDER, lytis);
        		map.put(TAG_LINK, nuoroda);
        		contactList.add(map);
        	}
        } catch (JSONException e) {
        	e.printStackTrace();
        }
        ListAdapter adapter = new SimpleAdapter(this, contactList,R.layout.list_item,
        		new String[] {TAG_NAME, TAG_EMAIL, TAG_GENDER, TAG_LINK}, new int[] { R.id.name, R.id.email, R.id.gender, R.id.link});
        
        setListAdapter(adapter);
        
        ListView lv = getListView();
        lv.setOnItemClickListener(new OnItemClickListener(){
        	public void onItemClick(AdapterView<?> parent, View view, int position, long id){
        		String name = ((TextView)view.findViewById(R.id.name)).getText().toString();
        		String email = ((TextView)view.findViewById(R.id.email)).getText().toString();
        		String lytis = ((TextView)view.findViewById(R.id.gender)).getText().toString();
        		String nuoroda = ((TextView)view.findViewById(R.id.link)).getText().toString();
        		
        		Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
        		in.putExtra(TAG_NAME, name);
        		in.putExtra(TAG_EMAIL, email);
        		in.putExtra(TAG_GENDER, lytis);
        		in.putExtra(TAG_LINK, nuoroda);
        		startActivity(in);

Code:
TextView txtName = (TextView) findViewById(R.id.txtName);
		TextView txtEmail = (TextView) findViewById(R.id.txtEmail);
		TextView txtGender = (TextView) findViewById(R.id.txtGender);
		TextView txtFile = (TextView) findViewById(R.id.txtFile);
		
		Intent i = getIntent();
		String name = i.getStringExtra("vardpav");
		String email = i.getStringExtra("email");
		String gender = i.getStringExtra("lytis");
		String link = i.getStringExtra("nuoroda");
		txtName.setText(name);
		txtEmail.setText(email);
		txtGender.setText(gender);
		try {
		    // Create a URL for the desired page
		    URL url = new URL(link);

		    // Read all the text returned by the server
		    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
		    String str;
		    while ((str = in.readLine()) != null) {
		        txtFile.setText(str);
		    	// str is one line of text; readLine() strips the newline character(s)
		    }
		    in.close();
		} catch (MalformedURLException e) {

			System.out.println("CHACHACHA");
		} catch (IOException e) {
		}
		
		Button btnImage = (Button) findViewById(R.id.imageButton);
		btnImage.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0){
				Intent i = new Intent(SingleMenuItemActivity.this,ImageActivity.class);
				startActivity(i);
 
Back
Top Bottom