I want a string then the ListView to display the same line of image and string again, but to do this a Showing the string is the left and right of the image. How can I determine how I am still learning Java and can not understand it.
MainActivity
Public Squared MainActivity Extends ActionBarActivity {string color_names [] = {"red", "green", "blue", "yellow", "pink", "Brown"}; Integer image_id [] = {R.drawable.red, R.drawable.green, R.drawable.blue, R.drawable.yellow, R.drawable.pink, R.drawable.brown}; String number_list [] = {"one", "two", "three", "four", "five", "six"}; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main); Customist adapter adapter = new customist adapter (this, image_id, color_name, number_list); ListView lv = (ListView) findViewById (R.id.listView); Lv.setAdapter (adapter); } @ Override Public Boolean On Crate Option Menu (Menu Menu) {// Enhancing Menu; It adds the item to the Action Bar if it exists GetMenuInflater (). Fulao (R.MenuMenu_man, menu); Back true; } @ Override selected public boolean on option Itam (Menuitm item) {// handles action bar items, click here Action bar automatically clicks the Home / up button, so // as long as you AndroidManifest.xml Specify basic activity. Int id = item.getItemId (); // Notice Simple Effectiveness (ID == RID.action_settings) {returns correct; } Return Super.Options item selected (item); }}
customlist adapter
public class customistAuderArrayAdapter {String [] color_names; String [] number_list; Integer [] image_id; Reference Reference; Public customist adapter (reference of activity, integer [] image_id, string [] color_names, string [] text) {super (references, rl.litt_ro, text); // To-O Auto-Generated Constructor Stub This.color_names = text; This.image_id = image_id; This.number_list = text; This.context = context; } @Override Public View getView (integer position, view convertView, ViewGroup parent) {// TODO auto-created method stub LayoutInflater inflater = (LayoutInflater) reference .getSystemService (Context.LAYOUT_INFLATER_SERVICE); View single_orror-flater.inflate (R.layout.list_row, empty, true); TextView TextView = (TextView) single_row.findViewById (R.id.textView); ImageView imageView = (ImageView) single_row.findViewById (R.id.imageView); TextView Text View1 = (TextView) single_row.findViewById (R.id.textList); TextView.setText (color_names [status]); ImageView.setImageResource (image_id [status]); TextView1.setText (number_list [status]); Return single_o; }}
list_row
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: orientation = "horizontal" & gt; Android: Android: Layout_margin = "10 DP" Android: layout_marginTop = "10dp" Android: layout_marginBottom = "10dp" Android: & lt; TextView Android: Android: Layout_width = "Wrap-Content": Layout_Gravity = "Center_Worldly" Android: Text = "TextView" /> & Lt; Android: layout_width = "wrap_content" android: layout_height = "wrap_content" /> & Lt; Android: layout_heigh = "wrap_content" android: layout_marginLeft = "10dp" Android: layout_marginRight = "10dp" Android: layout_marginTop = "10dp" Android: layout_marginbottom: textView android: id = "@ + id / textList" Android: layout_width = "wrap_content" = "10 DP" Android: layout_gravity = "center_for" Android: text = "textview1" /> & Lt; / LinearLayout & gt;
itemprop = "text">
public customlistadapter (activity reference, Integer [] image_id, string [] color_names, string [] text) {super (references, r.lit.list_ro, text); // To-O Auto-Generated Constructor Stub This.color_names = text; This.image_id = image_id; This.number_list = text; This.context = context; }
You must this.color_names = color_names; this.color_names = text instead of
;
Basically, your string arrays have the same value, which is why you have the same string near the image.
You should also use a look at the view holder pattern and how to convertView
and if you should look at Java Naming conventions. You must use camelcase. > CustomListAdapter, color_names - -> colorNames, etc ...
for example Customlistadapter
No comments:
Post a Comment