Note that there are some explanatory texts on larger screens.

plurals
  1. POListview special adapter change column background orientation change
    primarykey
    data
    text
    <p>I have the following problem. The list shows well in portrait mode. But when i switch to landscape, the background of items get scrambled/reverse order. </p> <p>For example:</p> <pre><code>column 1 Column2(a) Column 3(b) Column 4(c) 1 2(red) 3 4 12 36(orange) 87(red) 32 94 55 44 23(orange) </code></pre> <p>Now i turn to landscape and my list looks like this:</p> <pre><code>column 1 Column2(a) Column 3(b) Column 4(c) 1 2 3 4(orange) 12 36(orange) 87(red) 32 94 55(red) 44 23 </code></pre> <p>the data stays the same, the background colors are switched.</p> <p>inside my specialadapter i have a getView like this: SpecAdapter_list.java</p> <pre><code> public class SpecAdapter_list extends SimpleAdapter { public SpecAdapter_list(Context context, List&lt;HashMap&lt;String, String&gt;&gt; items, int resource, String[] from, int[] to) { super(context, items, resource, from, to); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); if (convertView == null) { // i have a listitem.xml wich lays-out each row in the list. // several textviews are hidden. // i check these hidden textviews on specific text. // if it has the text, we change the background of a specific column item. TextView c1 = (TextView) view.findViewById(R.id.c1); String c1_text=(String)a.getText(); TextView Columnitema = (TextView) view.findViewById(R.id.Columnitema); if(c1_text.equals("YES")) { Columnitema.setBackgroundColor(0xFFe10000); Columnitema.setTextColor(0xFFFFFFFF); } else if(c1_text.equals("NO")) { Columnitema.setBackgroundColor(0xFFff9600); Columnitema.setTextColor(0xFFFFFFFF); } TextView c2 = (TextView) view.findViewById(R.id.c2); String c2_text=(String)c2.getText(); TextView Columnitemb = (TextView) view.findViewById(R.id.Columnitemb); if(c2_text.equals("PERHAPS")) { Columnitemb.setBackgroundColor(0xFFe10000); Columnitemb.setTextColor(0xFFFFFFFF); } else if(c2_text.equals("ABSOLUTELY")) { Columnitemb.setBackgroundColor(0xFFff9600); Columnitemb.setTextColor(0xFFFFFFFF); } TextView c3 = (TextView) view.findViewById(R.id.c3); String c3_text=(String)c3.getText(); TextView Columnitemc = (TextView) view.findViewById(R.id.Columnitemc); if(c3_text.equals("PERHAPS")) { Columnitemc.setBackgroundColor(0xFFe10000); Columnitemc.setTextColor(0xFFFFFFFF); } else if(c3_text.equals("ABSOLUTELY")) { Columnitemc.setBackgroundColor(0xFFff9600); Columnitemc.setTextColor(0xFFFFFFFF); } } return view; } } </code></pre> <p>MainActivity.java</p> <pre><code>package com.z_list_columnitembackground; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import com.z_list_columnitembackground.R; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.ListView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView lv= (ListView)findViewById(R.id.listview); // create the grid item mapping String[] from = new String[] {"rowid", "col_1", "col_2", "col_3", "c1_status","c2_status","c3_status"}; int[] to = new int[] { R.id.LI_Number, R.id.Columnitema, R.id.Columnitemb, R.id.Columnitemc, R.id.c1, R.id.c2, R.id.c3 }; // prepare the list of all records List&lt;HashMap&lt;String, String&gt;&gt; fillMaps = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); // for(int i = 0; i &lt; 10; i++){ HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); map.put("rowid", "1"); map.put("col_1", "2"); map.put("col_2", "3"); map.put("col_3", "4"); map.put("c1_status", "YES"); map.put("c2_status", ""); map.put("c3_status", ""); fillMaps.add(map); HashMap&lt;String, String&gt; map2 = new HashMap&lt;String, String&gt;(); map2.put("rowid", "12"); map2.put("col_1", "36"); map2.put("col_2", "87"); map2.put("col_3", "32"); map2.put("c1_status", "NO"); map2.put("c2_status", "PERHAPS"); map2.put("c3_status", ""); fillMaps.add(map2); HashMap&lt;String, String&gt; map3 = new HashMap&lt;String, String&gt;(); map3.put("rowid", "94"); map3.put("col_1", "55"); map3.put("col_2", "44"); map3.put("col_3", "23"); map3.put("c1_status", ""); map3.put("c2_status", ""); map3.put("c3_status", "ABSOLUTELY"); fillMaps.add(map3); // } // fill in the grid_item layout SpecAdapter_list adapter = new SpecAdapter_list(this, fillMaps, R.layout.list_item, from, to); lv.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } </code></pre> <p>Strings.xml</p> <p> </p> <pre><code> &lt;string name="app_name"&gt;Z_list_alternatingcolors&lt;/string&gt; &lt;string name="menu_settings"&gt;Settings&lt;/string&gt; &lt;string name="LI_Number"&gt;1&lt;/string&gt; &lt;string name="Columnitema"&gt;dummya&lt;/string&gt; &lt;string name="Columnitemb"&gt;dummyb&lt;/string&gt; &lt;string name="Columnitemc"&gt;dummyc&lt;/string&gt; &lt;/resources&gt; </code></pre> <p>AndroidManifest</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.z_list_columnitembackground" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.z_list_columnitembackground.MainActivity" android:label="@string/app_name" android:windowSoftInputMode="stateHidden|adjustResize" android:configChanges="keyboardHidden|orientation"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    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. 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