Search This Blog

Monday, August 23, 2010

Experience - Configuring Android ListView

I have configured my ListView differently than the standard Android example. This article is what I did and how it was accomplished. The biggest difference between the android example and mine is I didn't want a full screen ListView. This impacted both the code and the visuals of the ListView. In the standard example it is suggested that a ListActivity is created. I on the other hand already have an Activity that defines a screen and is bound to a XML layout file. In the layout file I added a ListView element with the id MessageList. I then reference this ListView in my Activity and add the needed components to it. Below are excerpts from the Activity.

public class MessageActivity extends Activity {

private ListView mMessageList;
//Additional properties ...

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.messagepage);

//Bind XML objects
mMessageList = (ListView)findViewById(R.id.MessageList);
//...

//Additional setup and configuation
//...

//MessageList is a dummy content string array
//located in res/values/strings.xml
String[] mMessages =  

getResources().getStringArray(R.array.MessageList);

//Simple way for example
mMessageList.setAdapter(new ArrayAdapter(this,
android.R.layout.simple_list_item_1, mMessages));

// mMessageList.setAdapter(
// new EfficientAdapter(this, android.R.layout.simple_list_item_1,
// android.R.id.text1, mMessages));
}
}

 

At this point I have a ListView defined on a page with other content. The ListView is connected to an ArrayAdapter which supplies it with dummy content through a string array in res/values/strings.xml. Next I wanted to add a border to the ListView to help define its size and make it clear where the edges of the ListView were. I was surprised that it was so difficult to figure out. There is no border property in ListView which was disappointing. I tried various options and found the solution I like the best is putting the ListView in a FrameLayout. I set the Background color of the FrameLayout to the color I want for my border and set the padding to the desired border width. The results look something like this.

10 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. You truly did more than visitors’ expectations. Thank you for rendering these helpful, trusted, edifying and also cool thoughts on the topic to Kate.
    iosh course in chennai

    ReplyDelete
  3. You blog post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.

    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  4. Thank you for sharing such great information with us. I really appreciate everything that you’ve done here and am glad to know that you really care about the world that we live in...
    MySQL Online Training | MySQL Training Course

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. 2019 neural networks projects chennai, neural networks projects chennaiWe have real timing Cost, ENDDAD, MOV, VLSI, C), C++, NS2, Linux, dotnet, linux, mysql, web technologies, biomedical, strong, SSL, Wireless communicationPh. D / M.Phill / M.E / M.Tech /M.Sc (CSE)/MCA / MBA / B.Tech(CSE)/B.Sc./B.Sc./B.CA /research project centers in chennai

    ReplyDelete
  7. Best AWS Training provided by Vepsun in Bangalore for the last 12 years. Our Trainer has more than 20+ Years
    of IT Experience in teaching Virtualization and Cloud topics.. we are very delighted to say that Vepsun is
    the Top AWS cloud training Provider in Bangalore. We provide the best atmosphere for our students to learn.
    Our Trainers have great experience and are highly skilled in IT Professionals. AWS is an evolving cloud
    computing platform provided by Amazon with a combination of IT services. It includes a mixture of
    infrastructure as service and packaged software as service offerings and also automation. We have trained
    more than 10000 students in AWS cloud and our trainer Sameer has been awarded as the best Citrix and Cloud
    trainer in india.

    ReplyDelete