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 8796675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:40:38+00:00 2026-06-13T23:40:38+00:00

I have this code: ListView listView; static final String[] Liste = {Satz des Pythagoras,

  • 0

I have this code:

ListView listView;
static final String[] Liste = {"Satz des Pythagoras", "abc-Formel", "pq-Formel"};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    setTitle("CalcPlus");
    listView = getListView();
    //Own row layout
    listView.setAdapter(new ArrayAdapter<String>(this,
                R.layout.activity_home, Liste));
    listView.setOnItemClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_home, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.maths:
            return true;
        case R.id.physics:
            Intent myIntent2 = new Intent(Home.this, ActivityPhysics.class);
            startActivity(myIntent2);
        default:
            return super.onOptionsItemSelected(item);
    }
}
public void onItemClick(AdapterView<?> adapter, View view,
            int position, long id) {
    if ("Satz des Pythagoras".equals(Liste[position])) {
        Intent sdp = new Intent(view.getContext(), MainActivity.class);
        startActivityForResult(sdp, 0);
    }
    else if ("abc-Formel".equals(Liste[position])) {
        Intent abc = new Intent(view.getContext(), ActivityABC.class);
        startActivityForResult(abc, 0);
    }
    else if ("pq-Formel".equals(Liste[position])) {
        Intent pq = new Intent(view.getContext(), ActivityPQ.class);
        startActivityForResult(pq, 0);
    }
}

This should display a list and a actionbar.
It did, for some time.

It looks like I messed up the code and, since I’m not having that much experience, can’t find my mistake…so could someone review my code? 🙂

Because now it loads the activity..but doesn’t display the list or the actionbar 😮

Here is the XML in \menu\activity_home.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_settings"
    android:orderInCategory="100"
    android:showAsAction="never" />
<item android:id="@+id/maths"
    android:title="@string/maths"
    android:orderInCategory="1"
    android:showAsAction="always|withText" 
    android:titleCondensed="@string/maths" 
    android:icon="@drawable/ic_action_calculator" /> 
<item android:id="@+id/physics"
    android:icon="@drawable/ic_action_line_chart"
    android:title="@string/physics"
    android:orderInCategory="2"
    android:showAsAction="always|withText"/>

This is layout\activity_home.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/hello_world"/>

</RelativeLayout>

So basically it’s empty.

  • 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-13T23:40:39+00:00Added an answer on June 13, 2026 at 11:40 pm

    With these two lines:

    setContentView(R.layout.activity_home);
    ...
    listView.setAdapter(new ArrayAdapter<String>(this,
                R.layout.activity_home, Liste));
    

    You are using the same layout for the entire Activity and each row, which doesn’t make sense. The Activity’s layout should contain a ListView and the row layout shouldn’t…


    To use the default layouts, remove this line:

    setContentView(R.layout.activity_home);
    

    and change this one:

    listView.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, Liste));
    

    Also you need to onListItemClick() not onItemClick() to have the row clicks work.

    @Override
    protected void onListItemClick (ListView l, View v, int position, long id) {...}
    

    Okay now the only entry in LogCat is Array Adapter:”You musst supply a resource ID for a textview.

    You must give your TextView an id:

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"/>
    

    And change the way you create your adapter to:

    listView.setAdapter(new ArrayAdapter<String>(this,
                R.layout.activity_home, R.id.text, Liste));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how to see items that i pick on ListView ? i have this code:
Suppose we have this example: http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html with source code available here: http://code.google.com/p/myandroidwidgets/source/browse/trunk/Phonebook/src/com/abeanie/ How can
I am using this code to Implement the ListView with section: public class ListSample
I have the following code: Parallel.ForEach(this.listView2.CheckedItems, new ParallelOptions { MaxDegreeOfParallelism = 4 }, (CheckedItem)
I have this code <div id=main style=background:#aaaaaa;float:left;height:160px;margin:5px;position:relative;display:block;width:630px;> <div id=1 class=item style=background:#ffaacc;float:left;width:200px;height:150px;margin:5px;position:absolute;left:0px;top:0px;> </div> <div id=2
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this code for changing the image of a button: - (void)mouseEntered:(NSEvent *)event
I have this code in XAML <Grid x:Name=LayoutRoot Background=Transparent> <Grid.RowDefinitions> <RowDefinition Height=Auto/> <RowDefinition Height=*/>
I have this code: EditText value = ( EditText )findViewById( R.id.editbox ); Integer int_value
I have this code: ie1.link(:text, /Exception:/) It is producing an error message which I

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.