gilas1368
سه شنبه 12 فروردین 1393, 14:37 عصر
با سلام
دوستان من ی sliding menu دارم ک ی لیست و وقتی کاربر روی یکی از آیتم های اون لیست ضربه میزنه برنامه خطای زیر رو میده
117514
این کد فایل xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@android:color/white"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
اینم کد جاواش:
public class MainActivity extends Activity { private String[] mPlanetTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(navigation_layout);
mPlanetTitles = getResources().getStringArray(R.array.planets_arra y);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
View header = (View)getLayoutInflater().inflate(R.layout.img_lay out,null);
mDrawerList.addHeaderView(header);
// Set the adapter for the list view
mDrawerList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, mPlanetTitles));
mDrawerList.setOnItemClickListener(new ClickListener());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private class ClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
SelectItem(position);
}
}
private void SelectItem(int position) {
Fragment fragment = new PlanetFragment();
Bundle args = new Bundle();
args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
fragment.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.co ntent_frame, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mPlanetTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
private class PlanetFragment extends Fragment {
public static final String ARG_PLANET_NUMBER = "planet_number";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int i = getArguments().getInt(ARG_PLANET_NUMBER);
String planet = getResources().getStringArray(R.array.planets_arra y)[i];
Toast.makeText(getBaseContext(),planet,Toast.LENGT H_LONG).show();
return super.onCreateView(inflater, container, savedInstanceState);
}
}
}
برنامه روی اندروید 4 میشکلی نداره
اما زمانیک روی اندروید 2.2 run میکنم این خطا رو میده
ممنون میشم راهنمائیم کنین ببینم مشکلم کجاست:متفکر:
با تشکر
دوستان من ی sliding menu دارم ک ی لیست و وقتی کاربر روی یکی از آیتم های اون لیست ضربه میزنه برنامه خطای زیر رو میده
117514
این کد فایل xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@android:color/white"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
اینم کد جاواش:
public class MainActivity extends Activity { private String[] mPlanetTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(navigation_layout);
mPlanetTitles = getResources().getStringArray(R.array.planets_arra y);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
View header = (View)getLayoutInflater().inflate(R.layout.img_lay out,null);
mDrawerList.addHeaderView(header);
// Set the adapter for the list view
mDrawerList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, mPlanetTitles));
mDrawerList.setOnItemClickListener(new ClickListener());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private class ClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
SelectItem(position);
}
}
private void SelectItem(int position) {
Fragment fragment = new PlanetFragment();
Bundle args = new Bundle();
args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
fragment.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.co ntent_frame, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mPlanetTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
private class PlanetFragment extends Fragment {
public static final String ARG_PLANET_NUMBER = "planet_number";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int i = getArguments().getInt(ARG_PLANET_NUMBER);
String planet = getResources().getStringArray(R.array.planets_arra y)[i];
Toast.makeText(getBaseContext(),planet,Toast.LENGT H_LONG).show();
return super.onCreateView(inflater, container, savedInstanceState);
}
}
}
برنامه روی اندروید 4 میشکلی نداره
اما زمانیک روی اندروید 2.2 run میکنم این خطا رو میده
ممنون میشم راهنمائیم کنین ببینم مشکلم کجاست:متفکر:
با تشکر