Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code> First Create the List view by using the Base adapter : As Follows Create two layout files and One java file : main.xml &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF"&gt; &lt;ListView android:id="@+id/listviewText" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#FFFFFF"&gt;&lt;/ListView&gt; &lt;/LinearLayout&gt; textview.xml &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;TextView android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="match_parent" android:textSize="15dip" android:focusable="false" &gt;&lt;/TextView&gt; &lt;/LinearLayout&gt; Activity code is package com.pac.marico; import java.util.ArrayList; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; public class ListViewColor extends Activity { /** Called when the activity is first created. */ ArrayList&lt;String&gt; arrayList; Listviewlistneer listviewlistneer; ListView listView; int jumposition; int jumpCount = -1; View JumpView = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listView = (ListView)findViewById(R.id.listviewText); arrayList = new ArrayList&lt;String&gt;(); arrayList.add("ABC"); arrayList.add("XYZ"); arrayList.add("PQR"); arrayList.add("ABC"); arrayList.add("XYZ"); arrayList.add("PQR"); arrayList.add("ABC"); arrayList.add("XYZ"); arrayList.add("PQR"); arrayList.add("ABC"); arrayList.add("XYZ"); arrayList.add("PQR"); arrayList.add("ABC"); arrayList.add("XYZ"); arrayList.add("PQR"); arrayList.add("ABC"); arrayList.add("XYZ"); arrayList.add("PQR"); arrayList.add("ABC"); arrayList.add("XYZ"); arrayList.add("PQR"); arrayList.add("ABC"); arrayList.add("XYZ"); arrayList.add("PQR"); ListviewAdapter listviewAdapter = new ListviewAdapter(); listView.setAdapter(listviewAdapter); listviewlistneer = new Listviewlistneer(); } class ListviewAdapter extends BaseAdapter { @Override public int getCount() { // TODO Auto-generated method stub return arrayList.size(); } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View view, ViewGroup parent) { View rowView = view; Viewholder viewholder = null; if(rowView == null) { LayoutInflater layoutInflater = LayoutInflater.from(ListViewColor.this); rowView = layoutInflater.inflate(R.layout.textview, null); viewholder = new Viewholder(); viewholder.textView = (TextView)rowView.findViewById(R.id.textview); rowView.setTag(viewholder); } else { viewholder = (Viewholder)rowView.getTag(); } viewholder.textView.setTag(position); viewholder.textView.setText(arrayList.get(position)); if(jumpCount == position) { JumpView = rowView; rowView.setBackgroundColor(Color.RED); } else { rowView.setBackgroundColor(Color.TRANSPARENT); } listView.setOnItemClickListener(listviewlistneer); return rowView; } } class Listviewlistneer implements OnItemClickListener { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position,long id) { jumposition = position; int temp = 0; if(jumpCount == -1) { view.setBackgroundColor(Color.RED); jumpCount = jumposition; JumpView = view; temp = 1; } if(temp == 0) { if(jumpCount == jumposition) { view.setBackgroundColor(Color.RED); JumpView = view; } else { JumpView.setBackgroundColor(Color.TRANSPARENT); view.setBackgroundColor(Color.RED); jumpCount = jumposition; JumpView = view; } } } } class Viewholder { TextView textView; } } </code></pre> <p>Just Try it now. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload