Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6551539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:21:01+00:00 2026-05-25T12:21:01+00:00

I’m using a ListView to display an array of names. Code for it looks

  • 0

I’m using a ListView to display an array of names.
Code for it looks like this:

public class Imenik extends ListActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  final String[] seznam = getResources().getStringArray(R.array.seznam_array);
  setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, seznam));

  final ListView lv = getListView();
  lv.setTextFilterEnabled(true);

  lv.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
            if ("Baj And".equals(seznam[position]))
            { Intent i = new Intent(Imenik.this,Bajzelj.class); startActivity(i); lv.getItemIdAtPosition(position); }   
            else if ("Bes Jaz".equals(seznam[position]))
            { Intent i = new Intent(Imenik.this,Bajzelj.class); startActivity(i); }             
        }
      });
    } 

}

Now I would like to display this names into just one view (Only one name per choice) with different data (one xml file).

public class Bajzelj extends Activity {

int position;

    /** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    this.setTitle("Interni imenik");
    setContentView(R.layout.main);

    final String[] seznam = getResources().getStringArray(R.array.seznam_array);

    {
    if  ("Bajželj Andrej".equals(seznam[position]))
    {
        TextView ime = (TextView) findViewById(R.id.ime);
        ime.setText("And Baj");
        TextView telefon = (TextView) findViewById(R.id.telefon);
        telefon.setText("Telefon: +386 1 476");
        TextView gsm = (TextView) findViewById(R.id.mobitel);
        gsm.setText("GSM: +386 41 ");
        TextView skype = (TextView) findViewById(R.id.skype);
        skype.setText("Skype: ba+");
        TextView email = (TextView) findViewById(R.id.email);
        email.setText("E-pošta: and.baj@som.org");
        ImageView slika = (ImageView) findViewById(R.id.slika);
        slika.setImageResource(R.drawable.andbaj);          
    }
    else if ("Bes Jan".equals(seznam[position]))
    {
        TextView ime = (TextView) findViewById(R.id.ime);
        ime.setText("Jan Bes");
        TextView telefon = (TextView) findViewById(R.id.telefon);
        telefon.setText("Telefon: +386 1 4");
        TextView gsm = (TextView) findViewById(R.id.mobitel);
        gsm.setText("GSM: +386 41 75");
        TextView skype = (TextView) findViewById(R.id.skype);
        skype.setText("Skype: sf");
        TextView email = (TextView) findViewById(R.id.email);
        email.setText("E-pošta: Jan.Besej.si");
        ImageView slika = (ImageView) findViewById(R.id.slika);
        slika.setImageResource(R.drawable.besjaz);          
    }       
    }  
}

}

Is it possible to display them like this? I’m not a programmer so I’m having a lot of troubles with this one. I know that I should check for position somehow but I don’t know how to do this?

Thanks in advance to anybody who is willing to help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:21:02+00:00Added an answer on May 25, 2026 at 12:21 pm

    follow this more effective way.

    1. Use a Map object to store individual user data.
    2. Add these map objects to the List.
    3. Use custom adapter to display in the ListView.
    4. Whenever user clicks on particular list item, pass its position in intent.
    5. get position from Bundle and retrieve the particular user data from map of List.
    6. display all the data of the user.

    If you want a code snippet send me the user data fields i can send you the code snippet.

    here is the code.

    Test.java

    package com.test;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    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;
    
    public class Test extends Activity{
        public Map<String,Object> userData;
        public static List<Object> userList;
    
        String[] name = {"name_one","name_two","name_three","name_four","name_five"};
        String[] lastName = {"lastName_one","lastName_two","lastName_three","lastName_four","lastName_five"};
        String[] telephoneNumber = {"telephoneNumber_one","telephoneNumber_two","telephoneNumber_three","telephoneNumber_four","telephoneNumber_five"};
        String[] mobileNumber = {"mobileNumber_one","mobileNumber_two","mobileNumber_three","mobileNumber_four","mobileNumber_five"};
        String[] skypeUserName = {"skypeUserName_one","skypeUserName_two","skypeUserName_three","skypeUserName_four","skypeUserName_five"};
        String[] email = {"email_one","email_two","email_three","email_four","email_five"};
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            userList = new ArrayList<Object>();
            for(int i=0;i<5;i++){
                userList.add(getUserData(i));
            }       
            ListView lv = (ListView)findViewById(R.id.list);
            ListCustAdapter adapter = new  ListCustAdapter(this, userList);
            lv.setAdapter(adapter);     
            lv.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                        long arg3) {
                    Intent i = new Intent(Test.this,Test2.class); 
                    i.putExtra("position", position);
                    startActivity(i);
    
                }
            });     
        }
    
        public Map<String,Object> getUserData(int i){
            userData = new HashMap<String,Object>();
            userData.put("name", name[i]);
            userData.put("lastName", lastName[i]);
            userData.put("telephoneNumber", telephoneNumber[i]);
            userData.put("mobileNumber", mobileNumber[i]);
            userData.put("skypeUserName", skypeUserName[i]);
            userData.put("email", email[i]);
            return userData;
        }
    }
    

    Test2.java

    package com.test;    
    import java.util.Map;    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class Test2 extends Activity{
        TextView name,lname,phono,cellno,sky,email;
    
        @SuppressWarnings("unchecked")
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.test2);
            Bundle bundle = getIntent().getExtras();  
            int position = bundle.getInt("position");
            name = (TextView)findViewById(R.id.name);
            lname = (TextView)findViewById(R.id.last_name);
            phono = (TextView)findViewById(R.id.telephoneNumber);
            cellno = (TextView)findViewById(R.id.mobileNumber);
            sky = (TextView)findViewById(R.id.skypeUserName);
            email = (TextView)findViewById(R.id.email);
    
            name.setText((String)((Map<String,Object>)Test.userList.get(position)).get("name"));
            lname.setText((String)((Map<String,Object>)Test.userList.get(position)).get("lastName"));
            phono.setText((String)((Map<String,Object>)Test.userList.get(position)).get("telephoneNumber"));
            cellno.setText((String)((Map<String,Object>)Test.userList.get(position)).get("mobileNumber"));
            sky.setText((String)((Map<String,Object>)Test.userList.get(position)).get("skypeUserName"));
            email.setText((String)((Map<String,Object>)Test.userList.get(position)).get("email"));
    
        }
    }
    

    ListCustAdapter.java

    package com.test;
    
    import java.util.List;
    import java.util.Map;
    import android.app.Activity;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.TextView;
    
    public class ListCustAdapter extends BaseAdapter {
        public Activity context;    
        private List<Object> list;
    
        public ListCustAdapter(Activity context, List<Object> list) {
            super();
            this.context = context;
            this.list = list;       
        }
    
        @Override
        public int getCount() {
            return list.size();
        }
    
        @Override
        public Object getItem(int position) {
            return null;
        }
    
        @Override
        public long getItemId(int position) {
            return 0;
        }
    
        @SuppressWarnings("unchecked")
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            TextView tv = new TextView(context);
            tv.setText((String) ((Map<String, Object>) list.get(position)).get("name"));
            return tv;
        }
    }
    

    main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
    
      <ListView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:id = "@+id/list"
        />
    
    </LinearLayout>
    

    test2.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:id = "@+id/name"/>
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:id = "@+id/last_name"/>
        <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:id = "@+id/telephoneNumber"/>
        <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:id = "@+id/mobileNumber"/>
        <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:id = "@+id/skypeUserName"/>
        <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:id = "@+id/email"/>
    
    
    </LinearLayout>
    

    AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.test"
          android:versionCode="1"
          android:versionName="1.0">
    
    
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".Test"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
             <activity android:name=".Test2"/>
        </application>
    </manifest>
    

    Then run and enjoy……!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.