• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Listview with a textview and an imageview

Hi everyone,

as the title says I'm having a problem with incorporating an imageview with a textview into a list view.

Activity code:

Code:
ListView menuList = (ListView) findViewById(R.id.ListView_Menu);
        
        String[] menuitems = {getResources().getString(R.string.playgamebtn),
        		getResources().getString(R.string.viewscoresbtn),
        		getResources().getString(R.string.settingsbtn),
        		getResources().getString(R.string.helpbtn)};
        
        
        ArrayAdapter<String> adapt = new ArrayAdapter<String>(this, R.layout.menu_item, menuitems);
        menuList.setAdapter(adapt);
        

menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {

            	
            	TextView textView = (TextView)itemClicked.findViewById(R.id.label);
                String strText = textView.getText().toString();
                
                
                if (strText.equalsIgnoreCase(getResources().getString(R.string.playgamebtn))) {

                	
                	startActivity(new Intent(QuizMenuActivity.this, QuizGameActivity.class));
                
                } else if (strText.equalsIgnoreCase(getResources().getString(R.string.settingsbtn))) {

                	
                	startActivity(new Intent(QuizMenuActivity.this, QuizSettingsActivity.class));
                
                } else if (strText.equalsIgnoreCase(getResources().getString(R.string.helpbtn))) {

                	
                	startActivity(new Intent(QuizMenuActivity.this, QuizHelpActivity.class));
                
                } else if (strText.equalsIgnoreCase(getResources().getString(R.string.viewscoresbtn))) {

                	
                	startActivity(new Intent(QuizMenuActivity.this, QuizScoresActivity.class));
                }
            
            }
        });




Menu Item layout

Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

	android:layout_width="fill_parent" android:layout_height="wrap_content">


	<ImageView android:id="@+id/icon" android:layout_height="wrap_content"

		android:src="@drawable/menubtnimg" android:layout_width="22px"
		android:gravity="right" android:layout_gravity="right">


	</ImageView>


	<TextView xmlns:android="http://schemas.android.com/apk/res/android"

		android:text="@+id/TextView01" android:layout_width="fill_parent"
		android:id="@+id/label" android:gravity="center_horizontal"

		android:textSize="@dimen/menuitemsize" android:layout_centerInParent="true"
		android:layout_height="fill_parent" android:shadowRadius="5"
		android:textColor="@color/menu_color" android:shadowColor="@color/menu_glow"
		android:shadowDy="3" android:shadowDx="3"></TextView>

	<ImageView android:id="@+id/icon" android:layout_height="wrap_content"
		android:src="@drawable/menubtnimg" android:layout_width="22px"
		android:gravity="left" android:layout_gravity="left">


	</ImageView>

</LinearLayout>

Ok, displaying the imageview and the textview isn't the problem it is clicking on it. When clicking on the textview, there is an error with the ArrayAdapter.

If I am doing something fundamentally wrong, please tell me
 
Back
Top Bottom