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 6868153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:23:56+00:00 2026-05-27T03:23:56+00:00

I have an application with tabs. In one tab I need to put data

  • 0

I have an application with tabs. In one tab I need to put data (strings) in rows. To do so I chose tableLayout but when I wanted to use a contextmenu on its rows it doesn’t work.

I can show the contextmenu onLongClick but the problem is that I can’t get the info about the selected row to edit or delete the selected row. Then I read in a discussion that using listView is better than tablelayout if we have many rows. But the examples I saw extend listactivity but I don’t want to do this.

So when I try working on a listView without extending listactivity I don’t know how to do it what I mean is that I’ve never used listView before so I try different examples I found on the internet to understand it but it’s not working. Here’s what I did so far for the listView:

String [] items=getRessources().getStringArray(R.arra.resolution);
 //Resolution is an array of strings
ListView lv=(ListeView) findViewById(R.id.listView);
v.setAdapter(new ArrayAdapter<string>(this, android.R.layout.simple_list_item_1, items);

When I compile it I get a list with elements of my array in it but first, I want to change the color of text which I can’t. And secondly I want to add rows dynamically to the list which I don’t know how to do either. I think I have to use an adapter to do it but I don’t know how.
Can someone please guide me through this. I just want to know how to attach my list to an adapter which’ll allow me to dynamically add rows, add contextMenu etc.

  • 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-27T03:23:56+00:00Added an answer on May 27, 2026 at 3:23 am

    main Activity class:

    import java.util.ArrayList;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.Button;
    import android.widget.ListView;
    
    public class SelectedActivity extends Activity {
    
    private SelectedAdapter selectedAdapter;
    private ArrayList<String> list;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.selected_example);
    
        // populate the model - a simple a list
        list = new ArrayList<String>();
        list.add("Apple");
        list.add("Orange");
        list.add("Grape");
        list.add("Grape1");
        list.add("Grape2");
        list.add("Grape3");
        list.add("Grape4");
        list.add("Grape5");
        list.add("Grape6");
    
        // create our SelectedAdapter
        selectedAdapter = new SelectedAdapter(this,0,list);
        selectedAdapter.setNotifyOnChange(true);
    
        ListView listview = (ListView) findViewById(R.id.listExample);
        listview.setAdapter(selectedAdapter);
    
        listview.setOnItemClickListener(new OnItemClickListener() {
            //@Override
            public void onItemClick(AdapterView arg0, View view,
                                           int position, long id) {
                // user clicked a list item, make it "selected"
                selectedAdapter.setSelectedPosition(position);
            }
        });
    }
    

    Adapter class:

       import java.util.List;
        import android.content.Context;
        import android.graphics.Color;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.ArrayAdapter;
        import android.widget.Button;
        import android.widget.TextView;
    
        public class SelectedAdapter extends ArrayAdapter{
    
            // used to keep selected position in ListView
            private int selectedPos = -1;   // init value for not-selected
    
            public SelectedAdapter(Context context, int textViewResourceId,
                           List objects) {
                 super(context, textViewResourceId, objects);
            }
            public void setSelectedPosition(int pos){
            selectedPos = pos;
                 // inform the view of this change
                 notifyDataSetChanged();
            }
            public int getSelectedPosition(){
                 return selectedPos;
            }
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                     View v = convertView;
                     // only inflate the view if it's null
                     // if (v == null) {
                            LayoutInflater vi =   (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            v = vi.inflate(R.layout.selected_row, null);
                     //  }
    
                     // get text view
                         TextView label = (TextView)v.findViewById(R.id.txtExample);
                         Button btn=(Button)v.findViewById(R.id.btn1);
    
                         // change the row color based on selected state
                         if(selectedPos == position){
                            label.setBackgroundColor(Color.CYAN);
                            btn.setBackgroundResource(R.drawable.next);
                         }
                         else{
                            label.setBackgroundColor(Color.WHITE);
                         }
    
                         label.setText(this.getItem(position).toString());       
                         return(v);
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tab bar iPhone application with 4 tabs. In the Interface Builder
I'm developing an iPhone application that have a TabBarController with two tabs. Each tab
I have several tabs in my application, and each tab loads a different sub-page
Here's my problem: I've have an application with tabs. in each tab I have
I have a .NET forms application using a tab control with several tabs. There
I have an Application with two Tabs in WPF. One is Used to add
I am developing a tab bar application. I have five tabs in it. For
I have an application made by a UITabBar with three tabs. One of these
I have an Android application which has four tabs (I use a main TabActivity
I have a form with 3 tabs: one tab is for user entry and

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.