Issue
when i open the app my content view ("hello world") is not displayed. just listview appears but it must be shown when i swipe. here is my codes:
package com.example.temp;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView drawerList = (ListView)findViewById(R.id.first);
String[] myStringArray = getResources().getStringArray(R.array.right1);
drawerList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,myStringArray));
final ActionBar actionBar=getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
}
my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:orientation = "vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World" />
</LinearLayout>
<ListView
android:id="@+id/first"
android:layout_width="120dip"
android:layout_height="match_parent"
android:background="#00FF00"
android:divider="#FFFFFF"
android:dividerHeight="2dp"
android:gravity="left" >
</ListView>
</android.support.v4.widget.DrawerLayout>
and my strings:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">temp</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string-array name="right1">
<item name="1*1">1*1</item>
<item name="1*2">1*2</item>
<item name="1*3">1*3</item>
<item name="1*4">1*4</item>
<item name="1*5">1*5</item>
<item name="1*6">1*6</item>
<item name="1*7">1*7</item>
<item name="1*8">1*8</item>
<item name="1*9">1*9</item>
</string-array>
Solution
You've got an incorrect attribute in your ListView xml definition.
android:gravity="left"
should be
android:layout_gravity="left"
Answered By - Mike M.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.