Im an android newbie so please forgive me...
This is my code:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.adapter_who_row, null);
viewHolder.nameTextView = (TextView) convertView.findViewById(R.id.text);
viewHolder.companyTextView = (TextView) convertView.findViewById(R.id.whoRowCompany);
viewHolder.dotView = convertView.findViewById(R.id.whoRowDot);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
String textToShow = dataArray.get(position);
viewHolder.nameTextView.setText(textToShow);
viewHolder.dotView.setBackgroundColor(getResources().getColor(R.color.red));
viewHolder.companyTextView.setText("Test");
return convertView;
}
class ViewHolder {
TextView nameTextView;
TextView companyTextView;
View dotView;
}
dotView doesn't change its colour...
However, the two textVies does change their text.
What could it be?
Edit:
The xml is holding two editTexts and one View.
Below is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_centerVertical="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.85"
android:layout_gravity="center"
android:gravity="center">
<View
android:id="#+id/whoRowDot"
android:layout_width="40px"
android:layout_height="40px"
android:backgroundTint="#color/noteColor">
</View>
<!--android:background="#drawable/round_button"-->
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:background="#color/clear"
android:layout_weight="0.15">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="0dp"
android:text="User Name"
android:fontFamily="Roboto-Light"
android:background="#color/clear"/>
<TextView
android:id="#+id/whoRowCompany"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:text="Company"
android:textColor="#color/lightGrey"
android:background="#color/clear"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Thanks
remove this line from your xml view and try:
android:backgroundTint="#color/noteColor"
Related
is there any code to declare the imageview and set imageresource without inflate the layout ?
i am create listview adapter in other layout, so i didnt inflate the layout.
but ineed to set image to the imageview.
this is my code but its not working
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_item_list_request, container, false);
setHasOptionsMenu(true);
rlRequestWorkflow = (RelativeLayout)getActivity().findViewById(R.id.rlListRequestWorkflow);
listPhoto = (ImageView)getActivity().findViewById(R.id.listPhoto);
rlRequestWorkflow.addView(listPhoto);
}
this is my current layout (main class)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/flRequest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context="com.ITK.SMP.Native.Workflow.ListRequest">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:background="#ffffff">
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lvRequest"
android:choiceMode="singleChoice"
android:nestedScrollingEnabled="false"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
this is listadapter class
public class ListRequestAdapter extends ArrayAdapter<ListRequestItem> {
ImageView listPhoto;
public ListRequestAdapter(Context context, List<ListRequestItem> items)
{
super(context, R.layout.style_fragment_list_request, items);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if(convertView == null) {
// inflate the GridView item layout
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.style_fragment_list_request, parent, false);
// initialize the view holder
viewHolder = new ViewHolder();
viewHolder.tvTanggal = (TextView) convertView.findViewById(R.id.tvTanggalRequest);
viewHolder.tvTipe = (TextView) convertView.findViewById(R.id.tvTipeRequest);
viewHolder.tvStatus = (TextView) convertView.findViewById(R.id.tvStatus);
viewHolder.permitid = "";
convertView.setTag(viewHolder);
} else {
// recycle the already inflated view
viewHolder = (ViewHolder) convertView.getTag();
}
// update the item view
ListRequestItem item = getItem(position);
viewHolder.tvTanggal.setText(item.tanggal);
viewHolder.tvTipe.setText(item.tipe);
viewHolder.tvStatus.setText(item.status);
viewHolder.permitid = item.permitid;
return convertView;
}
private static class ViewHolder {
TextView tvTanggal;
TextView tvTipe;
TextView tvStatus;
String permitid;
}
}
this is the imageview in the listadapterlayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="reqtag"
android:id="#+id/rlListRequestWorkflow"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:weightSum="1"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.2"
android:orientation="vertical"
android:layout_height="wrap_content">
<!--ImageView here-->
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/listPhoto"
android:layout_width="65dp"
android:layout_height="63dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_menu_camera"
android:layout_marginTop="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.8"
android:orientation="vertical"
android:layout_height="wrap_content">
<!--All textViews here-->
<TextView
android:layout_width="100dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Type"
android:textSize="18dp"
android:fontFamily="sans-serif"
android:textColor="#color/black"
android:id="#+id/tvTipeRequest"
android:width="130dp" />
<TextView
android:layout_width="100dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Date"
android:fontFamily="sans-serif"
android:id="#+id/tvTanggalRequest"
android:textSize="15dp"
android:width="130dp" />
<TextView
android:layout_width="100dp"
android:layout_weight="1"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:text="Status"
android:textSize="15dp"
android:fontFamily="sans-serif"
android:id="#+id/tvStatus"
android:layout_column="38" />
</LinearLayout>
</LinearLayout>
any help would be appreciated
If you don't want to inflate your imageview, then pass your imageview in the constructor of class, and set the image from there.
Suppose, MainActivity is the class where your image view is present
MainActivity.class
ImageView imageview;
imageview=(ImageView)findViewById(R.Id.imageview);
new ListAdapter(imageview);
ListAdapter.class
ImageView imageview;
//constructor
public ListAdapter(ImageView imageview){
this.imageview=imageview;
}
//now you can use imageview to set image
Edit this:-
rlRequestWorkflow = (RelativeLayout)view.findViewById(R.id.rlListRequestWorkflow);
listPhoto = (ImageView)view.findViewById(R.id.listPhoto);
I'm trying to implement a custom list view which has list items with spinner and edittext. And the list item needs to be selectable, also the edittext in list item needs to be editable. But the problem is when I set the edittext editable with setFocusable(true), the list item isn't selectable, and when I set the edittext not editable with setFocusable(false), the list item is selectable. Does anyone know how to solve this?
Below is my code
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = inflater.inflate(R.layout.listitem, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.view1 = (Spinner) listItemView.findViewById(R.id.view1);
viewHolder.view2 = (EditText) listItemView.findViewById(R.id.view2);
viewHolder.view1.setFocusable(false);
viewHolder.view2.setFocusable(false);
viewHolder.view1.setAdapter(view1Adapter);
viewHolder.view1.setOnItemSelectedListener(this);
viewHodler.view2.setOnFocusChangeListener(this);
listItemView.setTag(viewHolder);
}
CustomListItem item = listViewItemList.get(position);
ViewHolder viewHolder = listItemView.getTag();
viewHolder.view1.setSelection(item.view1Value);
viewHolder.view1.setTag(item);
viewHolder.view2.setText(item.view2Value);
viewHolder.view2.setTag(item);
return listItemView;
}
===== updated to add xml =====
Below is my xml files for list view and item.
For list view.
<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="match_parent"
android:orientation="vertical"
android:background="#FFFFFF"
tools:context="namespace">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<ListView android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:listSelector="#AAAAAA"
android:background="#FFFFFF"
android:descendantFocusability="beforeDescendants" />
<TextView android:id="#android:id/empty" android:layout_width="match_parent"
android:layout_height="match_parent" android:gravity="center"
android:text="#string/empty"/>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/add"
android:id="#+id/btn_add" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/delete"
android:id="#+id/btn_delete" />
</LinearLayout>
</LinearLayout>
For list item.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"
android:weightSum="3">
<Spinner
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<EditText
android:id="#+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/empty"
android:layout_weight="2"
android:textSize="15sp"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:descendantFocusability="beforeDescendants"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Spinner
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<EditText
android:id="#+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/empty"
android:layout_weight="2"
android:textSize="15sp"
android:inputType="number" />
</LinearLayout>
Finally I found a solution for this requirement, however it requires a bit code works and it was different with what I expected at first.
Anyway below is a code block from my list adapter which implements AdapterView.OnItemSelectedListener, View.OnFocusChangeListener and View.OnTouchListener
private EditText activatedEditText;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = inflater.inflate(R.layout.listitem, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.view1 = (Spinner) listItemView.findViewById(R.id.view1);
viewHolder.view2 = (EditText) listItemView.findViewById(R.id.view2);
viewHolder.view1.setFocusable(false);
viewHolder.view2.setFocusable(false);
viewHolder.view1.setOnTouchListener(this);
viewHolder.view2.setOnTouchListener(this);
viewHolder.view1.setAdapter(view1Adapter);
viewHolder.view1.setOnItemSelectedListener(this);
viewHodler.view2.setOnFocusChangeListener(this);
listItemView.setTag(viewHolder);
}
CustomListItem item = listViewItemList.get(position);
ViewHolder viewHolder = listItemView.getTag();
viewHolder.view1.setSelection(item.view1Value);
viewHolder.view1.setTag(item);
viewHolder.view2.setText(item.view2Value);
viewHolder.view2.setTag(item);
return listItemView;
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if(v.getClass() == EditText.class) {
activatedEditText = (EditText)v;
activatedEditText.setFocusable(true);
activatedEditText.setFocusableInTouchMode(true);
activatedEditText.requestFocus();
}
else {
activatedEditText.clearFocus();
activatedEditText.setFocusable(false);
activatedEditText.setFocusableInTouchMode(false);
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(activatedEditText.getWindowToken(), 0);
}
}
I'm having a problem that all my ListViews Items are showing like this:
As you guys can see Hello World! is a TextView and is showing perfectly.
But the ListView itens are showing like they are disabled.
This is my Activity's onCreate method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open_answers);
ctx = getApplicationContext();
Intent intent = getIntent();
usersurvey_id = intent.getIntExtra("usersurvey_id", -1);
list = (ListView) findViewById(R.id.listview_answers);
getAnswers();
AnswersArrayAdapter adapter = new AnswersArrayAdapter(ctx, answersList);
list.setAdapter(adapter);
list.setClickable(false);
list.setEnabled(true);
}
This is my Custom Adapter:
#Override
public View getView(int position, View convertView, ViewGroup parent){
Answers answerItem = answersList.get(position);
ViewHolder holder;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.listitem_answers, null);
holder = new ViewHolder();
holder.question = (TextView) convertView.findViewById(R.id.tv_texto_pergunta);
holder.answer = (TextView) convertView.findViewById(R.id.tv_texto_resposta);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.question.setText(getQuestionById(answerItem.getAnswer_question_id()));
holder.answer.setText(answerItem.getAnswer_answer());
return convertView;
}
Activity layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.seven.questionario.OpenAnswers">
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/listview_answers"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
And ListView Item Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tv_pergunta"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Pergunta:"
android:background="#D0D0D0"/>
<TextView
android:id="#+id/tv_texto_pergunta"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:layout_below="#id/tv_pergunta"
android:text="Texto da pergunta"
android:background="#D0D0D0"/>
<View
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_texto_pergunta"
android:background="#drawable/dotted"
/>
<TextView
android:id="#+id/tv_resposta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_texto_pergunta"
android:text="Resposta:"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_texto_resposta"
android:layout_width="fill_parent"
android:layout_height="80sp"
android:layout_below="#id/tv_resposta"
android:text="Texto da resposta" />
<View
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:layout_below="#id/tv_texto_resposta"
/>
I now this is a bit old but i just stumbled across this post.
Could it be that you're using the wrong context? I think you should pass the current context of your Activity, like so:
ctx = getContext();
or like this:
AnswersArrayAdapter adapter = new AnswersArrayAdapter(this, answersList);
try this.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D0D0D0">
<TextView
android:id="#+id/tv_pergunta"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Pergunta:"/>
<TextView
android:id="#+id/tv_texto_pergunta"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:layout_below="#id/tv_pergunta"
android:text="Texto da pergunta"/>
<View
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_texto_pergunta"
android:background="#drawable/dotted"
/>
<TextView
android:id="#+id/tv_resposta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_texto_pergunta"
android:text="Resposta:"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_texto_resposta"
android:layout_width="fill_parent"
android:layout_height="80sp"
android:layout_below="#id/tv_resposta"
android:text="Texto da resposta" />
<View
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:layout_below="#id/tv_texto_resposta"
/>
Show your theme(application/activity) selected in AndroidManifest.xml. I guess it's the problem.
I followed #Aun tip and solved my problem.
I just had to set manually all my app's colors.
try this line
android:textColor="#000000" in your TextView
im using a listview to display a picture and a name. The problem im having is when i fling the listview it has a very choppy scroll. Im using the Android query lib to load the images. I get a lot of GC_FOR ALLOC freed in the logcat. Not sure what is causing it. Any help please?
listview 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="70dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:src="#drawable/grey2" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:src="#drawable/grey2" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
getview method:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
// convertView = null;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.layout, parent, false);
holder = new ViewHolder();
holder.pic=(ImageView)convertView.findViewById(R.id.pic);
holder.fname=(TextView)convertView.findViewById(R.id.fname);
holder.name=(TextView)convertView.findViewById(R.id.name);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
aq2= aq.recycle(convertView);
holder.name.setText(first_name + " " + last_name );
holder.username.setText(username);
q2.id(holder.pic).image(urrl);
return convertView;
}
static public class ViewHolder {
TextView fname;
TextView name;
ImageView pic;
}
Above is the main screen of my app with a custom adapter for listview. How do I put a different icon for each row in the listview? I tried putting an ImageView in the xml but it overwrites my whole screen only showing an icon.
MainAcitivty xml:
<?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:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/hp_color"
tools:context=".MainActivity" >
<TextView
android:id="#+id/cityText"
style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textSize="28sp" />
<ImageView
android:id="#+id/condIcon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_below="#id/cityText"
android:contentDescription="weather icon" />
<TextView
android:id="#+id/condDescr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/condIcon"
android:textSize="20sp" />
<ListView
android:id="#+id/mainListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<ImageButton
android:id="#+id/btnPicturePage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="picturePage"
android:src="#drawable/photo" />
Custom adapter:
public class WeatherAdapter extends ArrayAdapter<String> {
private final Activity context;
private ArrayList<String> weatherData;
static class ViewHolder {
public TextView text;
public ImageView image;
}
public WeatherAdapter(Activity context, ArrayList<String> weatherData) {
super(context, R.layout.list, weatherData);
this.context = context;
this.weatherData = weatherData;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
// reuse views
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.list, null);
// configure view holder
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) rowView.findViewById(R.id.rowTextView);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
ArrayList<String> s = new ArrayList<String>(weatherData);
String []sa = new String [s.size()];
sa = s.toArray(sa);
holder.text.setText(sa[position]);
if (sa[position].startsWith("Air pressure")) {
rowView.setBackgroundResource(R.color.skyblue) ;
}
return rowView;
}
List xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rowTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:textColor="#color/white" >
</TextView>
Your list.xml should be something similar to this (taken from one my files)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:gravity="center_vertical" android:orientation="horizontal"
android:background="#drawable/xml_pressed_bg" android:clickable="true" android:layout_width="fill_parent"
android:layout_height="54dip"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ttshow="http://schemas.android.com/apk/res-auto">
<ImageView android:id="#+id/imgThumb" android:layout_width="42.0dip" android:layout_height="42.0dip" android:scaleType="fitXY"
android:src="#drawable/sample_dj" />
<TextView android:textSize="14.0sp" android:textColor="#ff666666" android:id="#+id/txtName"
android:layout_width="180dip" android:layout_height="wrap_content"
android:singleLine="true" android:shadowColor="#99ffffff" style="#style/TextShadowLight"
android:text="Hello" android:paddingLeft="10dip"/>
</LinearLayout>
Every row item has an image (imgThumb). This needs to be changed or set to a static image, depending on your needs. This is done in the adapters' getView() method.
imgThumb.setImageResource(R.drawable.my_image);
Private TypedArray img;
img=getResource.obtainTypedArray(R.array.imgIcon)
if (sa[position].startsWith("Air pressure")) {
rowView.setBackgroundResource(R.color.skyblue) ;
holder.image.setImageResource(img.gerResourceId[0]);
}else if (sa[position].startsWith("Air Condition")) {
holder.image.setImageResource(img.gerResourceId[1]);
}