I'm trying to do an app with listView, which is need to be filled from another class... I'm basicly follow this site: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/ but somehow my adapter doesn't work right... And do not fill my listView...
I create a new object from my main class like: fillLeftMenu lmenu = new fillLeftMenu(menu);
I used this line for having started the activity, if it's not wrong:
startActivity(new Intent("com.yahya.training.FILLLEFTMENU"));
On my AndroidManifest.xml, i added this following lines:
<activity
android:name=".fillLeftMenu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.yahya.training.FILLLEFTMENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And the fillLeftMenu class is:
public class fillLeftMenu extends ListActivity {
private ProgressDialog myProgressDialog = null;
private View menu;
ImageView findLocation;
Spinner cityList;
ListView leftList;
String [] textIndex;
Drawable [] imageIndex;
ArrayList<LeftListItems> Left;
listAdapter lAdapter;
public fillLeftMenu(View Lmenu) {
this.menu = Lmenu;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
findLocation = (ImageView) menu.findViewById(R.id.image_findLocation);
leftList = (ListView) menu.findViewById(R.id.list);
// add items to listView
Left = new ArrayList<LeftListItems>();
textIndex = new String[] {"Bugünün Fırsatları", "Son Dakika Bonusları", "Kadın", "Aile", "Çocuk", "Alışveriş", "Şehirden Kaçış", "Kışa Özel"};
imageIndex = new Drawable[] {leftList.getResources().getDrawable(R.drawable.kucukicon_01),leftList.getResources().getDrawable(R.drawable.kucukicon_02),leftList.getResources().getDrawable(R.drawable.kucukicon_03),leftList.getResources().getDrawable(R.drawable.kucukicon_04),leftList.getResources().getDrawable(R.drawable.kucukicon_05),leftList.getResources().getDrawable(R.drawable.kucukicon_06),leftList.getResources().getDrawable(R.drawable.kucukicon_07),leftList.getResources().getDrawable(R.drawable.kucukicon_08)};
lAdapter = new listAdapter(menu.getContext(), R.layout.list_item, Left);
leftList.setAdapter(lAdapter);
Runnable viewOrders = new Runnable(){
public void run() {
getIndex();
}
};
Thread thread = new Thread(null, viewOrders, "MagentoBackground");
thread.start();
myProgressDialog = ProgressDialog.show(fillLeftMenu.this,"Please wait...", "Retrieving data ...", true);
leftList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
private Runnable returnRes = new Runnable() {
public void run() {
if(Left != null && Left.size() > 0){
lAdapter.notifyDataSetChanged();
for(int i=0;i<Left.size();i++)
lAdapter.add(Left.get(i));
}
myProgressDialog.dismiss();
lAdapter.notifyDataSetChanged();
}
};
private void getIndex() {
try{
LeftListItems item = new LeftListItems();
for(int i=0; i<textIndex.length; i++) {
item.setText(textIndex[i]);
item.setImage(imageIndex[i]);
Left.add(item);
}
}
catch (Exception e) {
Log.e("BACKGROUND_PROC", e.getMessage());
}
runOnUiThread(returnRes);
}
private class listAdapter extends ArrayAdapter<LeftListItems> {
private ArrayList<LeftListItems> items;
private Context ctx;
public listAdapter(Context ctx, int textViewResourceId, ArrayList<LeftListItems> items) {
super(ctx, textViewResourceId, items);
this.ctx = ctx;
this.items = items;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
// LayoutInflater inflater = LayoutInflater.from(ctx);
// v = inflater.inflate(R.layout.list_item, null);
LayoutInflater vi = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_item, null);
}
LeftListItems index = items.get(position);
if(index != null) {
TextView text = (TextView) v.findViewById(R.id.text);
ImageView img = (ImageView) v.findViewById(R.id.icon);
if(text != null)
text.setText(index.getText());
if(img != null)
img.setBackgroundDrawable(index.getImage());
}
return v;
}
}
}
I think you are getting stuck in the loop in returnRes.
for(int i=0;i<Left.size();i++)
lAdapter.add(Left.get(i));
The Left variable is the data set in lAdapter and it has already been updated in the getIndex method. You don't need the loop here at all.
You don't have to create an object for the Activity. You should first learn how Activity works. Activity Fundamental
Take a look at this - Creating an object of Android Activity class
And please try to follow the tutorial exactly.
Here are some other tutorial you can start with. http://www.vogella.de/articles/AndroidListView/article.html
You'll find samples in Android SDK directory.
Related
I want to populate custom list view with Ted Talks from TED API, but nothing is shown. I have done all the efforts but nothing does it.
Here's my code
Fragment Class
public class TalksFragment extends ListFragment {
private ListView talkList;
private String TalkUrl = "https://api.ted.com/v1/talks.json?api-key=nm4nq9uyqg558m7z8axbu3be&order=created_at:desc&fields=media_profile_uris,photo_urls,speakers&offset=";
private HandleJSON obj;
private ProgressDialog m_ProgressDialog = null;
private ArrayList<TalksItems> TalkItemsArray = null;
private TalkListAdapter talkListAdapter;
private Runnable viewOrders;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View talks = inflater.inflate(R.layout.talk_list_frag, container, false);
talkList = (ListView) talks.findViewById(android.R.id.list);
return talks;
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
TalkItemsArray = new ArrayList<>();
this.talkListAdapter = new TalkListAdapter(getActivity(), android.R.layout.simple_list_item_1, TalkItemsArray);
talkList.setAdapter(this.talkListAdapter);
viewOrders = new Runnable(){
#Override
public void run() {
int Offset=0;
obj = new HandleJSON(TalkUrl + Offset);
obj.fetchJSON("Talks");
while (obj.parsingComplete);
TalkItemsArray = obj.getTalkItems();
getActivity().runOnUiThread(returnRes);
}
};
Thread thread = new Thread(null, viewOrders, "MagentoBackground");
thread.start();
m_ProgressDialog = ProgressDialog.show(getActivity(),
"Please wait...", "Retrieving data ...", true);
}
private Runnable returnRes = new Runnable() {
#Override
public void run() {
int size = TalkItemsArray.size();
if(TalkItemsArray != null && TalkItemsArray.size() > 0){
talkListAdapter.notifyDataSetChanged();
for(int i=0; i<size; i++)
talkListAdapter.add(TalkItemsArray.get(i));
}
m_ProgressDialog.dismiss();
talkListAdapter.notifyDataSetChanged();
}
};
private class TalkListAdapter extends ArrayAdapter<TalksItems>{
LayoutInflater inflater;
private ArrayList<TalksItems> items;
public TalkListAdapter(Context context, int textViewResourceId, ArrayList<TalksItems> items) {
super(context, textViewResourceId, items);
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.items = items;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
if(convertView == null)
view = inflater.inflate(R.layout.custom_list_talk, null);
else
view = convertView;
TalksItems TI = items.get(position);
if(TI != null){
TextView talkName = (TextView)view.findViewById(R.id.txtTalkName);
TextView speakerName = (TextView)view.findViewById(R.id.txtSpeakerName);
TextView talkDescription = (TextView)view.findViewById(R.id.txtTalkDescription);
ImageView talkImage = (ImageView)view.findViewById(R.id.talkImage);
talkName.setText(TI.getTalkName());
speakerName.setText(TI.getSpeakerName());
talkDescription.setText(TI.getTalkDescription());
talkImage.setImageURI(TI.getImageURL());
}
return view;
}
}
}
Where custom_list_talk is layout for custom list and talk_list_frag is layout for fragment having a listview with id "#android:id/list"
API is working correctly, data is coming correctly from API.
Problem is that it shows nothing in custom listview(or may be it is not inflating or etc)
EDIT
Foolish mistake. I didn't call getMethod.
As per your code you are using
obj = new HandleJSON(TalkUrl + Offset);
obj.fetchJSON("Talks");
It should be
obj = new HandleJSON(TalkUrl + Offset);
obj.fetchJSON("talks");//Note the case of KEY
JSON is Case Sensitive.
**Edit:**
Make sure you are not populating the
TalkItemsArray
In your code.
I'm trying to create a listview with different items within it. I want to use a switch statement to do this but I'm struggling to produce this I have created this with one XML layout how can I use multiple XML Layouts. I've attached my code - thank you in advance!
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_postlist);
this.generateDummyData();
ListView listView = (ListView) this.findViewById(R.id.postListView);
final PostItemAdapter itemAdapter = new PostItemAdapter(getApplicationContext(), this.generateDummyData());
listView.setAdapter(itemAdapter);
}
private ArrayList<PostData> generateDummyData() {
PostData data = null;
ArrayList<PostData> listData = new ArrayList<PostData>();
for (int i = 0; i < 20; i++) {
data = new PostData();
data.postTitle = "Person " + (i + 1)
+ " Name Surname";
data.postThumbUrl = null;
listData.add(data);
}
return listData;
}
// Get dummy data for Activity Feed
class PostDataTask extends AsyncTask<Integer, Void, Void> {
ArrayList<PostData> recentTracks;
#Override
protected Void doInBackground(Integer... page) {
try {
// Get a page of 15 tracks
// Simplified - getPage accepts 'page' and 'limit' parameters and returns a Collection<Track>
recentTracks = new ArrayList<PostData>();
Thread.sleep(3000);
PostData data = null;
for (int i = 0; i < 10; i++) {
data = new PostData();
data.postTitle = "Person " + (i + 1)
+ " Name is the Post Title from RSS Feed";
data.postThumbUrl = null;
recentTracks.add(data);
}
} catch (Exception e) {
}
return null;
}
#Override
protected void onPostExecute(Void result) {
ListView listView = (ListView) findViewById(R.id.postListView);
PostItemAdapter adapter = ((PostItemAdapter) ((HeaderViewListAdapter) listView.getAdapter()).getWrappedAdapter());
if (adapter == null) {
adapter = new PostItemAdapter(getApplicationContext(), recentTracks);
listView.setAdapter(adapter);
} else {
adapter.addAll(recentTracks);
adapter.notifyDataSetChanged();
}
}
}
public class PostItemAdapter extends ArrayAdapter<PostData> {
private final Context context;
private final ArrayList<PostData> items;
private int currentPage = 0;
public PostItemAdapter(Context context, ArrayList<PostData> recentTrackArrayList) {
super(context, 0, recentTrackArrayList);
this.context = context;
this.items = recentTrackArrayList;
}
public View getView(int position, View convertView, ViewGroup parent) {
View rowView;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.postitem,
parent, false);
}
final PostData item = items.get(position);
rowView = convertView;
ImageView thumbImageView = (ImageView) rowView
.findViewById(R.id.postThumb);
if (items.get(position).postThumbUrl == null) {
thumbImageView.setImageResource(R.drawable.postthumb_loading);
}
TextView postTitleView = (TextView) rowView
.findViewById(R.id.postTitleLabel);
postTitleView.setText(items.get(position).postTitle);
if (position == getCount() - 1) {
currentPage++;
new PostDataTask().execute(currentPage);
}
return convertView;
}
}
}
At first use ViewHolder pattern.
At second make interfase of Item which will include two methods:
getType() - which return the type of your item;
getView(LayoutInflater inflater, View convertView) - which return the view of row. Inside this method create ViewHolder instance, then inflate View parameter to VH and do some action with result view.
. Then create 2 (or how much u need) classes which would implement Item. Define methods. Then in ListAdapter in getView() call getView() of items and return it to list.
Using the view holder pattern won't work if your items are completely different.
For every item, you need to check what kind of item you want to display and inflate a different view depending on it (for example, using a switch as you said)
I have a listview, and i start an intent to fill it. But the list shows up with a default image and no text. It is supposed to show up with different images and text.
I have two arrays, one is in string type and the other one is in drawable type... But my list doesn't show me none of these that i wanted...
My ListActivity:
public class fillLeftMenu extends ListActivity {
private View menu;
ImageView findLocation;
Spinner cityList;
ListView leftList;
String [] textIndex;
Drawable [] imageIndex;
ArrayList<LeftListItems> Left;
listAdapter lAdapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dataTransfer dt = BonubonActivity.deneme;
menu = dt.getView();
findLocation = (ImageView) menu.findViewById(R.id.image_findLocation);
leftList = (ListView) menu.findViewById(R.id.list);
// add items to listView
Left = new ArrayList<LeftListItems>();
textIndex = new String[] {"Bugünün Fırsatları", "Son Dakika Bonusları", "Kadın", "Aile", "Çocuk", "Alışveriş", "Şehirden Kaçış", "Kışa Özel"};
imageIndex = new Drawable[] {leftList.getResources().getDrawable(R.drawable.kucukicon_01),leftList.getResources().getDrawable(R.drawable.kucukicon_02),leftList.getResources().getDrawable(R.drawable.kucukicon_03),leftList.getResources().getDrawable(R.drawable.kucukicon_04),leftList.getResources().getDrawable(R.drawable.kucukicon_05),leftList.getResources().getDrawable(R.drawable.kucukicon_06),leftList.getResources().getDrawable(R.drawable.kucukicon_07),leftList.getResources().getDrawable(R.drawable.kucukicon_08)};
lAdapter = new listAdapter(menu.getContext(), R.layout.list_item, Left);
leftList.setAdapter(lAdapter);
getIndex();
lAdapter.notifyDataSetChanged();
leftList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
finish();
}
private void getIndex() {
try{
LeftListItems item = new LeftListItems();
for(int i=0; i<textIndex.length; i++) {
item.setText(textIndex[i]);
item.setImage(imageIndex[i]);
Left.add(item);
lAdapter.add(Left.get(i));
}
}
catch (Exception e) {
Log.e("BACKGROUND_PROC", e.getMessage());
}
}
private class listAdapter extends ArrayAdapter<LeftListItems> {
private ArrayList<LeftListItems> items;
private Context ctx;
public listAdapter(Context ctx, int textViewResourceId, ArrayList<LeftListItems> items) {
super(ctx, textViewResourceId, items);
this.ctx = ctx;
this.items = items;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_item, null);
}
LeftListItems index = items.get(position);
if(index != null) {
TextView text = (TextView) v.findViewById(R.id.text);
ImageView img = (ImageView) v.findViewById(R.id.icon);
if(text != null)
text.setText(index.getText());
if(img != null)
img.setBackgroundDrawable(index.getImage());
}
return v;
}
}
}
Try calling getIndex() method before creating the adapter and setting it to the list. Like this:
getIndex();
//then create new adapter
lAdapter = new listAdapter(menu.getContext(), R.layout.list_item, Left);
leftList.setAdapter(lAdapter);
I have a ListView that is being populated with collection of items using a custom adapter. One of the properties of the collection is a count, and I have two TextViews in my ListView layout, one for the text and one for the count. I'd like not to display the count TextView if the count is zero. The code I have works fine when the ListView is initially loaded, but when I scroll the ListView, the count will show on random rows and constantly change if scroll the ListView up and down. This is the code I have:
public class Main extends ListActivity
{
private static CustomAdapter adapter = null;
#Override
public void onCreate(Bundle icicle)
{
List<Item> items = new ArrayList<Item>();
items = GetItems();
adapter = new CustomAdapter();
for (Item item : items)
adapter.addItem(item);
this.setListAdapter(adapter);
adapter.notifyDataSetChanged();
}
/* ADAPTER */
private class CustomAdapter extends BaseAdapter
{
private final List<Item> mData = new ArrayList<Item>();
private final LayoutInflater mInflater;
public CustomAdapter() {
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void addItem(Item item) {
mData.add(item);
}
#Override
public int getCount() {
return mData.size();
}
#Override
public Object getItem(int position) {
return mData.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
final ViewHolder holder;
final Item item = (Item)this.getItem(position);
if (convertView == null)
{
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.main, parent, false);
holder.text = (TextView)convertView.findViewById(R.id.text);
holder.count = (TextView)convertView.findViewById(R.id.count);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder)convertView.getTag();
}
holder.text.setText(item.getTitle());
if (item.getCount() > 0)
holder.count.setText(item.getCount().ToString());
else
holder.count.setVisibility(View.INVISIBLE);
return(convertView);
}
}
static class ViewHolder {
TextView text, count
}
Layout:
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
/>
EDIT:
I was able to get it working by doing a hacky workaround. It seems setting the TextView's visibility to Invisible or Gone was causing the issue, so I just changed the color of the items with a zero count to the background color:
if (item.getCount() > 0)
holder.count.setText(item.getCount().ToString());
else
holder.count.setTextColor(Color.WHITE);
If anyone has a real fix, please let me know.
You should just do this:
if (item.getCount() > 0) {
holder.count.setText(item.getCount().ToString());
holder.count.setVisibility(View.VISIBLE);
}
else
holder.count.setVisibility(View.INVISIBLE);
Because you use a ViewHolder, you need to consider the fact that you might get an old View that's not showing the count. This means we need to make sure that the visibility of count is set to VISIBLE. Equally we want to hide it if the count is zero - so we change the visibility even though we might get a View that is all ready invisible.
I think you wrong a part of your code, Amend test this code:
if (item.getCount() > 0)
holder.count.setText(item.getCount());
else
holder.count.setVisibility(View.INVISIBLE);
Please go through this code you may helpful for the same.
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.select);
mListUsers = getUsers();
lvUsers = (ListView) findViewById(R.id.lv_user);
s = new ListAdapter(this, R.id.lv_user, mListUsers);
lvUsers.setAdapter(s);
lvUsers.setClickable(true);
// lvUsers.setTextFilterEnabled(true);
lvUsers.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3)
{
Object o = lvUsers.getItemAtPosition(position);
UserBO obj = (UserBO) o;
Intent intent = new Intent(Select.this,Update.class);
intent.putExtra("pid", ""+obj.getId());
intent.putExtra("name", obj.getName());
//put data which you want to show and select.
startActivity(intent);
}
});
}
public ArrayList<UserBO> getUsers()
{
DBAdapter dbAdapter=DBAdapter.getDBAdapterInstance(this);
try {
dbAdapter.createDataBase();
} catch (IOException e) {
//Log.i("*** select ",e.getMessage());
}
dbAdapter.openDataBase();
String query="SELECT * FROM profiledatabase";
ArrayList<ArrayList<String>> stringList = dbAdapter.selectRecordsFromDBList(query, null);
dbAdapter.close();
ArrayList<UserBO> usersList = new ArrayList<UserBO>();
for (int i = 0; i < stringList.size(); i++) {
ArrayList<String> list = stringList.get(i);
UserBO user = new UserBO();
try {
user.pid = Integer.parseInt(list.get(0));
//write code to get data from table
} catch (Exception e) {
//Log.i("***" + Select.class.toString(), e.getMessage());
}
usersList.add(user);
}
return usersList;
}
// ***ListAdapter***
private class ListAdapter extends ArrayAdapter<UserBO> {
// --CloneChangeRequired
private ArrayList<UserBO> mList;
// --CloneChangeRequired
public ListAdapter(Context context, int textViewResourceId,ArrayList<UserBO> list) {
// --CloneChangeRequired
super(context, textViewResourceId, list);
this.mList = list;
}
public View getView(int position, View convertView, ViewGroup parent){
View view = convertView;
try
{
if (view == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.list_item, null);
// --CloneChangeRequired(list_item)
}
final UserBO listItem = mList.get(position);
// --CloneChangeRequired
if (listItem != null)
{
// setting list_item views
//( (TextView) view.findViewById(R.id.tv_pid) ).setText( listItem.getId()+"");
( (TextView) view.findViewById(R.id.tv_name) ).setText( listItem.getName() );
( (TextView) view.findViewById(R.id.tv_email)).setText(listItem.getEmail());
( (TextView) view.findViewById(R.id.tv_contact) ).setText( listItem.getContact()+"" );
}}catch(Exception e)
{
//Log.i(Select.ListAdapter.class.toString(), e.getMessage());
}
return view;
}
}
I wish to create a tab application in Android.
I wish to basically have four tabs in my application.
Namely, Home, Compose, Inbox, Sent.
I started with a TabContainer extending TabActivity, is this a correct approach.
Since i will be having MenuItem, which i used be having multiple views for Inbox, as such List of inbox, i sud be able to read, and then delete and all.
I wish to know how do I approach?
Basically i wish to make an application similar to gmail.
Any ideas, or direction might help me
public class Inbox extends ListActivity{
private ProgressDialog progressDialog = null;
private ArrayList<EmailElement> emailElement = null;
private InboxAdapter inboxAdapter;
private CheckBoxWithInboxList newInboxAdapter;
private Runnable beforeFetchingEmail;
private TextView emailFromTextView = null;
private TextView emailSubjectTextView = null;
ListView listView;
private static int mode = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inbox);
mode = this.getIntent().getIntExtra("EDIT_MODE", -1);
Log.i("EDITMODE", String.valueOf(mode));
emailElement = new ArrayList<EmailElement>();
if(mode ==0 || mode==-1){
this.inboxAdapter = new InboxAdapter(this, R.layout.inbox_row, emailElement);
setListAdapter(inboxAdapter);
}else{
this.newInboxAdapter = new CheckBoxWithInboxList(this, R.layout.inbox_row, emailElement);
setListAdapter(newInboxAdapter);
}
beforeFetchingEmail = new Runnable() {
#Override
public void run() {
getEmails();
}
};
Thread thread = new Thread(null, beforeFetchingEmail, "MagentoBackground");
thread.start();
progressDialog = ProgressDialog.show(Inbox.this,"Please wait...",
"Retrieving Emails ...", true);
listView = getListView();
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parentView, View view,
int position, long id) {
}
});
}
private Runnable returnRes = new Runnable() {
#Override
public void run() {
if(emailElement != null && emailElement.size() > 0){
if(mode==0 || mode==-1){
inboxAdapter.notifyDataSetChanged();
for(int i=0;i<emailElement.size();i++){
inboxAdapter.add(emailElement.get(i));
}
progressDialog.dismiss();
inboxAdapter.notifyDataSetChanged();
}else{
newInboxAdapter.notifyDataSetChanged();
for(int i=0;i<emailElement.size();i++){
newInboxAdapter.add(emailElement.get(i));
}
progressDialog.dismiss();
newInboxAdapter.notifyDataSetChanged();
}
}
}
};
private void getEmails(){
try{
emailElement = new ArrayList<EmailElement>();
EmailElement ee0 = new EmailElement();
ee0.setFrom("Robin Thapa");
ee0.setSubject("Urgent Meeting");
emailElement.add(ee0);
EmailElement ee1 = new EmailElement();
ee1.setFrom("Deepak Thapa");
ee1.setSubject("Staff meeting #Sunday");
emailElement.add(ee1);
Thread.sleep(5000);
}catch(Exception ex){
}
runOnUiThread(returnRes);
}
#Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.inbox_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.inboxEdit:
Intent intent = new Intent(this,EmailClient.class);
intent.putExtra("tabId", 2);
intent.putExtra("EDIT_MODE", 1);
startActivityForResult(intent, Intent.FILL_IN_DATA);
return true;
case R.id.inboxRefresh:
return true;
case R.id.inboxNext:
return true;
case R.id.inboxPrevious:
return true;
}
return false;
}
private class InboxAdapter extends ArrayAdapter<EmailElement>{
private ArrayList<EmailElement> items;
public InboxAdapter(Context context,int textViewResourceId,
ArrayList<EmailElement> items) {
super(context, textViewResourceId, items);
this.items = items;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.inbox_row, null);
}
EmailElement o = items.get(position);
if (o != null) {
CheckBox emailCheckBox = (CheckBox)view.findViewById(R.id.inboxCheckBoxId);
emailCheckBox.setVisibility(View.INVISIBLE);
emailFromTextView = (TextView) view.findViewById(R.id.inboxEmailFrom);
emailSubjectTextView = (TextView) view.findViewById(R.id.inboxEmailSubject);
if (emailFromTextView != null){
emailFromTextView.setText("From: "+o.getFrom());
}
if(emailSubjectTextView != null){
emailSubjectTextView.setText("Sub: ["+ o.getSubject()+"]");
}
}
return view;
}
}
private class CheckBoxWithInboxList extends ArrayAdapter<EmailElement>{
private ArrayList<EmailElement> items;
public CheckBoxWithInboxList(Context context,int textViewResourceId,
ArrayList<EmailElement> items) {
super(context, textViewResourceId, items);
this.items = items;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.inbox_row, null);
}
EmailElement o = items.get(position);
if (o != null) {
CheckBox emailCheckBox = (CheckBox)view.findViewById(R.id.inboxCheckBoxId);
emailCheckBox.setVisibility(View.VISIBLE);
emailFromTextView = (TextView) view.findViewById(R.id.inboxEmailFrom);
emailSubjectTextView = (TextView) view.findViewById(R.id.inboxEmailSubject);
if (emailFromTextView != null){
emailFromTextView.setText("From: "+o.getFrom());
}
if(emailSubjectTextView != null){
emailSubjectTextView.setText("Sub: ["+ o.getSubject()+"]");
}
}
return view;
}
}
}
For tablayout I recommend : http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
you might want to read up on this Tab Layout | Android Development
it's a good starting point