Go Back   Android Forums > Android Development > Application Development
Application Development Dev Lounge for the Coder Folks
Gamers - Check out our new sister sites!
Nintendo Wii U!    |    OUYA - $99 Android System!

test: Reply
 
LinkBack Thread Tools
Old March 21st, 2012, 03:08 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Mar 2012
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default JSON send string value

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);

shien is offline  
Reply With Quote
Sponsors
Reply
Tags
json


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:07 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.