Sunday, November 17, 2013

Listview not showing on orientation Change [android help]


Listview not showing on orientation Change



I have previously done a listview and the list is being displayed whether in landscape or portrait orientation. However, in my new app, when I decide to change orientation, whether landscape to portrait or vice versa, it does not load again. I am trying to populate the listview with items from sqlite database. Here is my code:


Attractions.java



public class Attractions extends ListActivity {
DataBaseHandler db = new DataBaseHandler(this);
ArrayList imageArry = new ArrayList();
ContactImageAdapter adapter;
int ctr, loaded;
int [] landmarkImages={R.drawable.oblation,R.drawable.eastwood,R.drawable.ecopark,R.drawable.circle};
String []landmarkDetails = { "Oblation", "Eastwood", "Ecopark", "QC Circle"};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_attractions);
ctr = db.checkContact(landmarkDetails[loaded]);
db.deleteAll();


// get image from drawable

/**
* CRUD Operations
* */
// Inserting Contacts
Log.d("Insert: ", "Inserting ..");


for(loaded=0; loaded
Bitmap image = BitmapFactory.decodeResource(getResources(),
landmarkImages[loaded]);

// convert bitmap to byte
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte imageInByte[] = stream.toByteArray();
Log.d("Going to load images", "Image "+ loaded);

Log.d("Goind to load objects", "loading");

if(ctr == 0){
Log.d("Nothing Loaded", "Loading Now");
db.addContact(new Contact(landmarkDetails[loaded], imageInByte));}
Log.d(landmarkDetails[loaded], "Loaded!");
image.recycle();
}


// Reading all contacts from database
List contacts = db.getAllContacts();
for (Contact cn : contacts) {
String log = "ID:" + cn.getID() + " Name: " + cn.getName()
+ " ,Image: " + cn.getImage();

// Writing Contacts to log
Log.d("Result: ", log);
//add contacts data in arrayList
imageArry.add(cn);

}
adapter = new ContactImageAdapter(this, R.layout.screen_list,
imageArry);
ListView dataList = (ListView) findViewById(android.R.id.list);
dataList.setAdapter(adapter);
}


UPDATE


I ran the app on portrait mode: list present, when switched to landscape: does not display anything. I switch to portrait again: list present again.



Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...