Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:07:36+00:00 2026-06-15T23:07:36+00:00

This is the code to my adapter: public class LogHistoryAdapter extends BaseAdapter { private

  • 0

This is the code to my adapter:

public class LogHistoryAdapter extends BaseAdapter {
private Context context = null;
private ArrayList<LogListItem> logList = null;

public LogHistoryAdapter(Context context) {
    this.context = context;
    logList = new ArrayList<LogHistoryAdapter.LogListItem>();

    LogListItem item1 = new LogListItem(Type.HEADER, "", "", "", "Wednesday, Jan 13 2012");
    logList.add(item1);
    LogListItem item2 = new LogListItem(Type.CLICKBLE, "ID ", "bla" , "Range 1m" , "");
    logList.add(item2);
    LogListItem item3 = new LogListItem(Type.CLICKBLE, "ID ", "bla" , "Range 1m" ,"");
    logList.add(item3);
    LogListItem item4 = new LogListItem(Type.CLICKBLE, "ID ", "bla" , "Range 1m", "" );
    logList.add(item4);
    LogListItem item5 = new LogListItem(Type.HEADER, "", "", "", "Tuesday, Jan 12 2012");
    logList.add(item5);
    LogListItem item6 = new LogListItem(Type.CLICKBLE, "ID ", "bla" , "Range 1m" , "");
    logList.add(item6);
    LogListItem item7 = new LogListItem(Type.CLICKBLE, "ID ", "bla" , "Range 1m" ,"");
    logList.add(item7);
    LogListItem item8 = new LogListItem(Type.CLICKBLE, "ID ", "bla" , "Range 1m" , "");
    logList.add(item8);
}

public enum Type {
    HEADER, CLICKBLE;
}

public class LogListItem {

    Type type;
    String name;
    String details;
    String id;
    String header;
    public LogListItem(Type type, String id, String name, String details, String header) {
        this.type = type;
        this.name = name;
        this.id = id;
        this.details = details;
        this.header = header;
    }


}

public int getCount() {
    return logList.size();
}

public Object getItem(int position) {
    return logList.get(position);
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View rowView, ViewGroup parent) {
    final SettingsViewHolder holder;
    LogListItem currentObj = logList.get(position);
    if (rowView == null) {

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rowView = inflater.inflate(R.layout.row_settings_log, parent, false);
        holder = new SettingsViewHolder();

        switch (currentObj.type) {
        case HEADER:
            holder.layout = (RelativeLayout) rowView.findViewById(R.id.settingsItemLayoutLog);
            holder.text = (TextView) rowView.findViewById(R.id.settingsItemLog);
            break;
        case CLICKBLE:
            holder.layout = (RelativeLayout) rowView.findViewById(R.id.settingsSubitem1LayoutLog);
            holder.text = (TextView) rowView.findViewById(R.id.settingsSubItem1TxtViewLog);
            holder.text2 = (TextView) rowView.findViewById(R.id.settingsSubItem1TxtView2Log);
            holder.text3 = (TextView) rowView.findViewById(R.id.settingsSubItem1TxtView3Log);
            break;
        default:
            break;

        }
        rowView.setTag(holder);

    } else {
        holder = (SettingsViewHolder) rowView.getTag();
    }
    switch (currentObj.type) {
    case HEADER:
        LogService.log("header", "header: " + currentObj.header);
        LogService.log("header", "id: " + currentObj.id);
        LogService.log("header", "name: " + currentObj.name);
        LogService.log("header", "details: " + currentObj.details);
        LogService.log("=====", "===============================");
        holder.layout.setVisibility(View.VISIBLE);
        holder.text.setText(currentObj.header);
        break;

    case CLICKBLE:
        holder.layout.setVisibility(View.VISIBLE);
        LogService.log("clickable", "header: " + currentObj.header);
        LogService.log("clickable", "id: " + currentObj.id);
        LogService.log("clickable", "name: " + currentObj.name);
        LogService.log("clickable", "details: " + currentObj.details);
        LogService.log("clickable", "===============================");
        holder.text.setText(currentObj.id);
        //                holder.text2.setText(currentObj.name);
        //                holder.text3.setText(currentObj.details);

        break;
    default:
        break;
    }

    return rowView;
}

static class SettingsViewHolder {
    CheckBox checked;
    TextView text;
    TextView text2;
    TextView text3;
    RelativeLayout layout;

}
}

Now this list looks similar to the one from the Android Settings page. It has headers, that only have the date in a TextView (Type.HEADER), and then it has buttons (Type.CLICKBLE). The problem is, that when it creates the list, after the second header (“Tuesday, Jan 12 2012”), the next button, which is CLICKBLE (item6) is created as a HEADER, and then the application crashes because, the HEADER has only 1 TextView, while the CLICKBLE type has 3 TextViews., so it crashes when i try to setText to the second TextView (being in HEADER, it doesn’t exist).
I need to know, why, the adapter, messes up my list, and it also messes up the type of the items.
Currently with this code, i don’t get a ANR error, but i cannot write the 2nd and 3rd texts to the CLICKBLE type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:07:37+00:00Added an answer on June 15, 2026 at 11:07 pm

    For what your attempt to achive you should also override getViewTypeCount() getItemViewType(int position). Call getItemViewType to choose what kind of view getView should use. getViewTypeCount has to return the number of different view you want to inflate (two in your case I think).

    public static final int NORMAL_ROW = 0;
    public static final int DARKGRAY_ROW = 1;
    @override
    public int getViewTypeCount() {
          return 2;
    }
    
    @override
    public int getItemViewType(int position) {
      LogListItem currentObj = logList.get(position);
      return (currentObj.type == HEADER) ? NORMAL_ROW :  DARKGRAY_ROW ;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

base adapter code public class ListAdapter extends BaseAdapter{ public ArrayList<HashMap<String,String>> list; Activity activity; public
I have this code public class MainActivity extends Activity { private static final int
I have downloaded this code from developer.android public class SpinnerTestActivity extends ActivityInstrumentationTestCase2<SpinnerActivity> { private
I have this code public class MyFragment extends SherlockFragment { public static Fragment newInstance(Context
İ am using this custom adapter for showing youtube thumbnail. public class MyMedyaAdapter extends
So i have this code: public class StreamingMp3Player extends Activity implements OnClickListener, OnTouchListener, OnCompletionListener,
I have the following code snippet. public class ImageStoreActivity extends ListActivity { private DBHelper
Let's look at this code: IList<IHouseAnnouncement> list = new List<IHouseAnnouncement>(); var table = adapter.GetData();
I have a main class filled with a cursor adapter: public class MainMenu extends
Here is my code in my Activity: public class GridViewActivity extends Activity { GridView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.