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

  • Home
  • SEARCH
  • 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 5958751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:35:16+00:00 2026-05-22T18:35:16+00:00

Here is the my code for the Dialog With ListView and here i also

  • 0

Here is the my code for the Dialog With ListView and here i also maintain the state when the user click on list it background will be fill with green as you can see in my image below

But problem that i have is below

1>I want to increase my row height .How can do?

2>and i also want to put image beside in all row is this possible?

Here is my image in which i want to put image beside all list items

Here is my code for all this stuff.

 package com.android.listselector;

 import java.util.ArrayList;
 import java.util.List;

 import android.app.Activity;
 import android.app.Dialog;
 import android.content.Context;
 import android.graphics.Color;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.AdapterView.OnItemClickListener;

  public class ListSelector extends Activity {
private SelectedAdapter selectedAdapter;
private ArrayList<String> list;
private Context mContext = ListSelector.this;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.selected_example);
    String[] items = { "lorem", "ipsum", "dolor", "sit", "amet",
            "consectetuer", "adipiscing", "elit", "morbi", "vel", "ligula",
            "vitae", "arcu", "aliquet", "mollis", "etiam", "vel", "erat",
            "placerat", "ante", "porttitor", "sodales", "pellentesque",
            "augue", "purus" };
    // populate the model - a simple a list
    list = new ArrayList<String>();
    for (int i = 0; i < items.length; i++) {
        list.add(items[i]);

    }
    // create our SelectedAdapter
    selectedAdapter = new SelectedAdapter(this, 0, list);
    selectedAdapter.setNotifyOnChange(true);

    Dialog dialog = new Dialog(mContext);
    dialog.setContentView(R.layout.selected_example);
    dialog.setTitle("Custom Dialog");
    ListView listview = (ListView) dialog.findViewById(R.id.listExample);

    listview.setAdapter(selectedAdapter);

    dialog.show();

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

// move up event handler

// move down event handler

// Move selected item "up" in the ViewList.
private void moveUp() {
    int selectedPos = selectedAdapter.getSelectedPosition();
    if (selectedPos > 0) {
        String str = list.remove(selectedPos);
        list.add(selectedPos - 1, str);
        // set selected position in the adapter
        selectedAdapter.setSelectedPosition(selectedPos - 1);
    }
}

// Move selected item "down" in the ViewList.
private void moveDown() {
    int selectedPos = selectedAdapter.getSelectedPosition();
    if (selectedPos < list.size() - 1) {
        String str = list.remove(selectedPos);
        list.add(selectedPos + 1, str);
        // set selected position in the adapter
        selectedAdapter.setSelectedPosition(selectedPos + 1);
    }
}

public class SelectedAdapter extends ArrayAdapter<String> {

    // used to keep selected position in ListView
    private int selectedPos = -1; // init value for not-selected

    public SelectedAdapter(Context context, int textViewResourceId,
            List<String> 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);

        // change the row color based on selected state
        if (selectedPos == position) {
            label.setBackgroundColor(Color.GREEN);
        } else {
            label.setBackgroundColor(Color.WHITE);
        }

        label.setText(this.getItem(position).toString());
        /*
         * // to use something other than .toString() MyClass myobj =
         * (MyClass)this.getItem(position);
         * label.setText(myobj.myReturnsString());
         */
        return (v);
    }
}

}

and here are the layout used in my code

  <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
       android:layout_height="fill_parent"
        android:orientation="vertical">


    <ListView
android:id="@+id/listExample"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#CCCCCC"
    android:choiceMode="singleChoice"
     />

     <LinearLayout
     android:orientation="horizontal"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="bottom"
     >
     <Button
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:id="@+id/btnMoveUp"
     />

     <Button
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:id="@+id/btnMoveDown"
     />

     </LinearLayout>

here is other one

   <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/txtExample" android:textSize="18sp" android:textColor="#000000"
android:background="#FF0000">
    </TextView>
  • 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-22T18:35:17+00:00Added an answer on May 22, 2026 at 6:35 pm

    Yes i get solution by here all my answer

    first i have to modify selected_row xml file by this

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="wrap_content" android:layout_height="100dip">
     <TextView android:layout_width="fill_parent"
        android:layout_height="40px" android:id="@+id/txtExample"
        android:textSize="18sp" android:textColor="#000000"
        android:gravity="center_vertical"
         />
    <ImageView android:layout_width="wrap_content"
        android:layout_height="40px" android:id="@+id/imgbeside"
        android:scaleType="center" android:layout_centerVertical="true"
        android:layout_alignParentRight="true" android:src="@drawable/selector"
        android:layout_marginRight="10dip" />
    

    and also in my java file i put the following thing below this line

      TextView label = (TextView) v.findViewById(R.id.txtExample);
      ImageView mImageview = (ImageView) v.findViewById(R.id.imgbeside); 
    

    this will work for me.Ok Thanks For all reponse.

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

Sidebar

Related Questions

Can I use progress bar in android, without the thread? HERE IS CODE OF
Here's the code: protected Dialog onCreateDialog(int id) { Dialog dialog = null; if (id
Here is the code I'm using http://jsbin.com/evike5/edit When the jQuery UI dialog is fired
Edit: The code here still has some bugs in it, and it could do
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
We have some old C code here that's built with nmake. Is there an
I am using pseudo-code here, but this is in JavaScript. With the most efficient
I have a piece of code here that i really could use some help
I've got this code here: SqlCommand CodeStatus = new SqlCommand(SQL, DB); DB.Open(); Reader =

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.