Identify AutocompleteTextView in ListView Item - java

I have a couple of AutocompleteTextView as items in ListView; these items are dynamically loaded using Custom adapter. When an item is selected in the AutoCompleteTextView, I need to update another TextView which is on the same row as the AutoCompleteTextView. I'm having trouble identifying position of AutoCompleteTextView where an item was selected. Any pointers would be appreciated:
My Activity looks like this, where Listview is defined:
<ListView
android:id="#+id/listview_orders"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
ListView Items are defined in another layout file as:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<AutoCompleteTextView
android:id="#+id/product_code_row_item"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:ems="10" />
<AutoCompleteTextView android:id="#+id/product_name_row_item"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView android:id="#+id/product_size_row_item"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
/>
</LinearLayout>
ListView adapter is being set as below:
ListView view = (ListView) findViewById(R.id.listview_orders);
ListViewItemAdapter adapter = new ListViewItemAdapter(this, orderItems, prodCodeList, prodNameList);
view.setAdapter(adapter);
Custom Adapter getView method implementation is as follows:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = activity.getLayoutInflater();
convertView = inflater.inflate(R.layout.order_list_row, null);
}
AutoCompleteTextView productCode = (AutoCompleteTextView ) convertView.findViewById(R.id.product_code_row_item);
AutoCompleteTextView productName = (AutoCompleteTextView) convertView.findViewById(R.id.product_name_row_item);
TextView productSize = (TextView) convertView.findViewById(R.id.product_size_row_item);
TextView mQty = (TextView) convertView.findViewById(R.id.product_mqty_row_item);
OrderItem orderItem = (OrderItem)orderItemList.get(position);
productCode.setText(orderItem.getProductCode());
productCode.setTag(position);
productName.setText(orderItem.getDescription());
productName.setTag(position);
productSize.setText(orderItem.getProductSize());
//Setting up autocorrect adapter for product codes
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(activity, android.R.layout.select_dialog_item, prodCodeList);
//Getting the instance of AutoCompleteTextView
productCode.setThreshold(1);//will start working from first character
productCode.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
productCode.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View arg1, int pos,
long id) {
Toast.makeText(OrderApplication.getCustomAppContext(), (CharSequence)parent.getItemAtPosition(pos), Toast.LENGTH_LONG).show();
int itemPosition = (Integer) arg1.getTag();
//loadOrderItem(newOrderItem, (String) parent.getItemAtPosition(pos), true);
}
});
//Setting up autocorrect adapter for product names
adapter = new ArrayAdapter<String>
(activity, android.R.layout.select_dialog_item, prodNameList);
//Getting the instance of AutoCompleteTextView
productName.setThreshold(2);//will start working from first character
productName.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
return convertView;
}

you should use -
adapter.getItem(pos)
inside your onItemClick

I found a workaround to get reference of AutoCompleteTextView in listview.
holder.productCodeView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus) {
currentFocusView = v;
}
}
});
holder.productCodeView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View arg1, int pos, long id) {
if (currentFocusView != null) {
int iPosition = (Integer) currentFocusView.getTag();
}
}
});

Related

duplicating all activity instead of [check boxes and text only] (To do list android app)

I'm trying to make to-do list app. the design here "https://i.ibb.co/cXnQ9dP/Capture.png"
I got box and text code from "https://www.vogella.com/tutorials/AndroidListView/article.html" proj (15.1. Interaction between the model and Listview) but I put the XML code into my existing XML activity [not in a new activity] and changed activity name in super(context, R.layout.rowbuttonlayout, list); and view = inflator.inflate(R.layout.rowbuttonlayout, null); to my main activity name
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mando.todolist.new_list">
.............background and buttons code here............
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="#id/plus"
android:orientation="horizontal"
android:paddingTop="205dp"
android:id="#+id/repeat_layout"
>
<CheckBox
android:id="#+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4px"
android:layout_marginRight="10px" >
</CheckBox>
<TextView
android:id="#+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="50px"
android:layout_alignRight="#id/check"
>
</TextView>
</LinearLayout>
public InteractiveArrayAdapter(Activity context, List<Model> list) {
super(context, R.layout.activity_new_list, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.activity_new_list.,null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
viewHolder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Model element = (Model) viewHolder.checkbox
.getTag();
element.setSelected(buttonView.isChecked());
}
});
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName());
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}
}
public class new_list extends ListActivity {
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// create an array of Strings, that will be put to our ListActivity
ArrayAdapter<Model> adapter = new InteractiveArrayAdapter(this,
getModel());
setListAdapter(adapter);
}
private List<Model> getModel() {
List<Model> list = new ArrayList<Model>();
list.add(get("Linux"));
list.add(get("Windows7"));
list.add(get("Suse"));
list.add(get("Eclipse"));
list.add(get("Ubuntu"));
list.add(get("Solaris"));
list.add(get("Android"));
list.add(get("iPhone"));
// Initially select one of the items
list.get(1).setSelected(true);
return list;
}
private Model get(String s) {
return new Model(s);
}
}
The output is All activity has been duplicated [including background and buttons] instead duplicating checkbox with text only in the same activity
Move your background and buttons to the xml file where you put your ListView
it should look like this, because the item xml you are using where your CheckBox exists is the one used for the ListView, if you but the button it will duplicated too
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- background and buttons code here -->
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:headerDividersEnabled="true"/>
</LinearLayout>

How to make card style menu in android

I want to add card style in my app like this
i use in my app mysql database so i need to make like this cards and put my data from database in it now i use ListView with this code
public void listAllItme() {
ListAdapter lA = new listAdapter(listitems);
listView.setAdapter(lA);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent open = new Intent(R_arabic.this, rewaya_show.class);
open.putExtra("name", listitems.get(position).name);
open.putExtra("url", listitems.get(position).url);
open.putExtra("img", listitems.get(position).img);
open.putExtra("num", listitems.get(position).num);
startActivity(open);
}
}
});
}
class listAdapter extends BaseAdapter {
ArrayList<listitem_gib> lista = new ArrayList<listitem_gib>();
public listAdapter(ArrayList<listitem_gib> lista) {
this.lista = lista;
}
#Override
public int getCount() {
return lista.size();
}
#Override
public Object getItem(int position) {
return lista.get(position).name;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = getLayoutInflater();
View view = layoutInflater.inflate(R.layout.row_item_gib, null);
TextView name = (TextView) view.findViewById(R.id.textView_gib);
ImageView img = (ImageView) view.findViewById(R.id.imageView_gib);
TextView num = (TextView) view.findViewById(R.id.textView_gib2);
TextView size = (TextView) view.findViewById(R.id.textView_gib3);
name.setText(lista.get(position).name);
num.setText(lista.get(position).num);
size.setText(lista.get(position).size);
Picasso.with(R_arabic.this).load("http://grassyhat.com/android/image/" + lista.get(position).img).into(img);
return view;
}
}
first i want to know how i can make like this card style
second how i can use this code with card menu not listview
sorry im new in android and sorry for my bad english
What do you mean by card menu? because the example in the image is a recyclerview with a cardview item, you can achieve this by doing something like this
This will be your activity
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView)findViewById(R.id.recyclerView);
//Just your list of objects, in your case the list that comes from the db
List<Items> itemsList = new ArrayList<>();
CardAdapter adapter = new CardAdapter(this, itemsList);
//RecyclerView needs a layout manager in order to display data so here we create one
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
//Here we set the layout manager and the adapter to the listview
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
}
Inside the layout file you just have to place the recyclerview like this
<RelativeLayout
android:id="#+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="jsondh.myapplication.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Then your adapter will be something like this
public class CardAdapter extends RecyclerView.Adapter<CardAdapter.CardViewHolder> {
private List<Items> itemsList;
private Activity activity;
public CardAdapter(Activity activity, List<Items> items){
this.activity = activity;
this.itemsList = items;
}
#Override
public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = activity.getLayoutInflater().inflate(R.layout.cardview_layout, parent, false);
return new CardViewHolder(itemView);
}
#Override
public void onBindViewHolder(CardViewHolder holder, int position) {
//Here you bind your views with the data from each object from the list
}
#Override
public int getItemCount() {
return itemsList.size();
}
public class CardViewHolder extends RecyclerView.ViewHolder {
public ImageView bookImage;
public TextView bookLabel01, bookLabel02;
public CardViewHolder(View itemView) {
super(itemView);
bookImage = (ImageView)itemView.findViewById(R.id.image);
bookLabel01 = (TextView)itemView.findViewById(R.id.label01);
bookLabel02 = (TextView)itemView.findViewById(R.id.label02);
}
}
And the last one will be the layout from each item on the list, like this
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardElevation="15dp"
app:cardBackgroundColor="#3369Ed">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/image"
android:layout_width="150dp"
android:layout_height="130dp"/>
<TextView
android:id="#+id/label01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Label"
android:layout_gravity="right"
android:padding="5dp"
android:textColor="#ffffff"/>
<TextView
android:id="#+id/label02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LongerLabel"
android:layout_gravity="right"
android:padding="5dp"
android:textColor="#ffffff"/>
</LinearLayout>
</android.support.v7.widget.CardView>
You also have to add this to your gradle file:
compile 'com.android.support:recyclerview-v7:25.0.0'
compile 'com.android.support:cardview-v7:25.0.0'
Hope it helps!
It's pretty simple. You will have to use a RecyclerView with GridLayoutManager and add a cardView to it.
Then, use an Adapter and ViewHolder to feed the data.
I suggest you to check this out:
https://developer.android.com/training/material/lists-cards.html

How to count the number of checkboxes ticked which is inside a listview

I have an custom array adaptor which is handling a list view.
Each row has two checkboxes. There are five rows in total.
I want to be able to count the number of checkboxes ticked and then display this number in Stand1
So basically the project Layout is like this
Inside stand1 there is a list view and a text view.
The stand1.java calls an array adapter Called CustomArrayAdaptor.
I want to be able to count the number of checkboxes clicked and send that data back to the stand1
I am quite new to android development so if somebody can be able to push me in the right direction, it would be great.
Here is my code
Stand1.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="446dp"
android:id="#+id/Stand1list"
android:scrollIndicators="right"
android:smoothScrollbar="true">
</ListView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Score To Databse"
android:id="#+id/sendtodb"
android:textSize="12dp"
android:clickable="true"
android:layout_below="#+id/Stand1list"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="8/10"
android:id="#+id/Score"
android:layout_marginLeft="33dp"
android:layout_marginStart="33dp"
android:layout_alignBottom="#+id/sendtodb"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="10dp" />
Row_Layout1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textelement"
xmlns:android="http://schemas.android.com/apk/res/android"
android:textSize="30dp"
android:textStyle="bold"
android:longClickable="false" />
<CheckBox
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/Checkbox1"
android:button="#drawable/checkboxcustom"
android:layout_marginLeft="50dp" />
<CheckBox
android:button="#drawable/checkboxcustom"
android:id="#+id/Checkbox2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="50dp" />
</LinearLayout>
Stand1.java
public class Stand1 extends Fragment {
ListView mList;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.stand1,container,false);
mList = (ListView) root.findViewById(R.id.Stand1list);
return root;
}
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
populateListView();
}
private void populateListView() {
String[] pair = {"Pair 1","Pair 2","Pair 3","Pair 4","Pair 5"};
//build adapter
ArrayAdapter<String> adapter = new CustomArrayAdaptor(getActivity(),pair);
mList.setAdapter(adapter);
}
}
CustomArrayAdaptor.java
public class CustomArrayAdaptor extends ArrayAdapter<String>{
public CustomArrayAdaptor(Context context, String [] Pairs) {
super(context, R.layout.row_layout1, Pairs);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View CustomView = inflater.inflate(R.layout.row_layout1, parent, false);
String stringelement = getItem(position);
TextView Text= (TextView)CustomView.findViewById(R.id.textelement);
Text.setText(stringelement);
return CustomView;
}
}
Thanks Folks
I added a few things to your CustomArrayAdaptor and tested it, see below:
public class CustomArrayAdapter extends ArrayAdapter<String> {
int checkAccumulator;
public CustomArrayAdapter(Context context, String [] Pairs) {
super(context, R.layout.row_layout1, Pairs);
checkAccumulator = 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View customView = inflater.inflate(R.layout.row_layout1, parent, false);
String stringelement = getItem(position);
TextView Text = (TextView) customView.findViewById(R.id.textelement);
CheckBox checkBox1 = (CheckBox) customView.findViewById(R.id.Checkbox1);
CheckBox checkBox2 = (CheckBox) customView.findViewById(R.id.Checkbox2);
CompoundButton.OnCheckedChangeListener checkListener = new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
countCheck(isChecked);
Log.i("MAIN", checkAccumulator + "");
}
};
checkBox1.setOnCheckedChangeListener(checkListener);
checkBox2.setOnCheckedChangeListener(checkListener);
Text.setText(stringelement);
return customView;
}
private void countCheck(boolean isChecked) {
checkAccumulator += isChecked ? 1 : -1 ;
}
}
Added int checkAccumulator to keep track of how many items have been clicked.
Added two CheckBox Views for the purpose of tracking checks.
Added CompoundButton.OnCheckedChangeListener that calls a new countCheck method everytime any checkBox is checked / unchecked. We pass the isChecked boolean to track whether we need to add or subtract from our checkAccumulator.
Added countCheck function that adds or subtracts 1 dependent on the boolean. Sorry for the obfuscated code, for all those who aren't used to the ? conditional it is basically saying if true add 1, else add -1.
Not sure what you wanted to do with the check count, so I added a Log.i("MAIN", checkAccumulator + ""); just so you can watch the Android Monitor to ensure that it is actually working.
Should work for you.
First of all, you should recycle your views in the adapter:
LayoutInflater inflater = LayoutInflater.from(getContext());
if (convertView == null) {
convertView = inflater.inflate(R.layout.row_layout1, parent, false);
}
After that, I think you should save the state of each checkbox in your data source or just keep a list, the same size of your pair array, and save it there using the position you get from getView.

How can I setText to a TextView in every single row of my ListView

Hi guys I am new to Android and also to stackoverflow, Greetings and thanks for the help.
I have 2 Xml files for the same activity. One that contains a ListView and the second as my custom layout for an ArrayAdapter that populates a ListView which is also included on my first layout:
<include android:id="#+id/lv" layout="#layout/lv_row" />
ListView Custom Layout (lv_row.xml):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/icon"
android:src="#drawable/ic_launcher"/>
<TextView
android:layout_toRightOf="#+id/icon"
android:layout_width="fill_parent"
android:layout_height="38dp"
android:textSize="30sp"
android:id="#+id/label"/>
<TextView
android:layout_toRightOf="#+id/icon"
android:layout_below="#+id/label"
android:layout_width="fill_parent"
android:layout_height="12dp"
android:gravity="bottom"
android:id="#+id/label2"
android:textSize="12sp"/>
</RelativeLayout>
This is my adapter:
final ArrayAdapter<String> Array = new ArrayAdapter<String>(this,R.layout.lv_row,R.id.label,myList);
I save strings one by one into "myList" and display them on my ListView, what I want to do is to enumerate the elements on my list view by using idNum.setText(iterating_variable.toString())... but it won't work because idNum always get the value that was set on the XML file.
This is the code I use to link the second XML with my Java code
lv = (RelativeLayout) findViewById(R.id.lv);
idNum = (TextView) lv.findViewById(R.id.label2);
Thanks again for your help.
create custom Adapter and setText() in getView() method of adapter
like
class CustomAdapter extends BaseAdapter {
private ArrayList<String> mList;
private LayoutInflater mInflater;
public CustomAdapter(ArrayList<String> list) {
mList = list;
mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return mList.size() ;
}
#Override
public Object getItem(int position) {
return mList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = mInflater.inflate(R.layout.lv_row, null);
((TextView) convertView.findViewById(R.id.label2)).setText(mList.get(position));
return convertView;
}
}
and set on ListView

Android ListView add not clickable TextView

I have list view:
<ListView android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
And I add some items to it:
final ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < items.length(); ++i) {
try {
list.add(items[i].getString("title"));
} catch (JSONException e) {
e.printStackTrace();
}
}
final StableArrayAdapter adapter = new StableArrayAdapter(this,
android.R.layout.simple_list_item_1, list);
listview.setAdapter(adapter);
But now I want to add some TextViews (at example if(i==5)) to the list, like a label. It should not be clickable.
How can I add it?
listview.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,long arg3)
{
long pos = arg0.getItemIdAtPosition(arg2);
if(pos != 5)
{
//add textview
}
else
{
//nothing
}
}
});
You should use a custom row layout instead of android.R.layout.simple_list_item_1, for example a row.xml you have one text view whose visibility is set to gone by default:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/nonclickable_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="#+id/normal_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Put it in res/layout/ folder, then call R.layout.row instead of android.R.layout.simple_list_item_1 when you create your StableArrayAdapter. In the getView() method
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView==null) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row, parent,false);
}
if(int position==5) {
TextView tv = (TextView)convertView.findViewById(R.id.nonclickable_text);
tv.setVisibility(View.VISIBLE);
}

Categories