gpt4 book ai didi

Android 自定义列表滑动菜单崩溃

转载 作者:行者123 更新时间:2023-12-02 03:18:39 25 4
gpt4 key购买 nike

我正在为我的项目创建自定义列表幻灯片菜单,在我完成尝试运行它后,每次都会因此错误而崩溃。文件第 1 行错误膨胀类

file line #1 error inflating class android.support.widget.drawerlayoutt

我的 XML:

http://pastebin.com/rx3UShfj

这是我的项目的全部代码:

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.transition.Slide;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnItemClickListener {

private DrawerLayout drawerLayout;
private ListView listView;
private ActionBarDrawerToggle drawerListener;
private MyAdapter myAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawerLayout = (DrawerLayout) findViewById(R.id.drawerList);
listView = (ListView) findViewById(R.id.listnewsView);
myAdapter = new MyAdapter(this);
listView.setAdapter(myAdapter);
listView.setOnItemClickListener(this);
drawerLayout = (DrawerLayout) findViewById(R.id.drawerList);
drawerListener = new ActionBarDrawerToggle(this, drawerLayout,
R.drawable.ic_slidelancher, R.string.drawer_open,
R.string.drawer_close) {
@Override
public void onDrawerClosed(View drawerView) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "Slide Menu Closed",
Toast.LENGTH_SHORT).show();
}

@Override
public void onDrawerOpened(View drawerView) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "Slide Menu Opened ",
Toast.LENGTH_SHORT).show();
}
};
drawerLayout.setDrawerListener(drawerListener);
getActionBar().setHomeButtonEnabled(true);
// highlight the home button on the top
getActionBar().setDisplayHomeAsUpEnabled(true);
// arrow to go back to home screen

}

// pop up the drawer when click on the name on the top (action bar )
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerListener.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
drawerListener.onConfigurationChanged(newConfig);
}

// sync the Drawer Layout with What the user see on screen ..
@Override
protected void onPostCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onPostCreate(savedInstanceState);
drawerListener.syncState();
// Bywdy el 3 icons so3'era lama ts7b el Menu w ykbrha lama trg3ha
}

@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;
}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
selectItem(position);
}

public void selectItem(int position) {
listView.setItemChecked(position, true);
}

public void setTitle(String title) {
getActionBar().setTitle(title);
}

class MyAdapter extends BaseAdapter {
private Context context;

String[] Slidelist;
int[] images = { R.drawable.ic_calendar, R.drawable.ic_chat,
R.drawable.ic_cnews, R.drawable.ic_cschdules };

public MyAdapter(Context context) {
this.context = context;
Slidelist = context.getResources().getStringArray(
R.array.arrayofNews);

}

@Override
public int getCount() {
// TODO Auto-generated method stub
return Slidelist.length;
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return Slidelist[position];
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater
.inflate(R.layout.custom_imageview, parent, false);

} else {
row = convertView;

}
TextView titleTextView = (TextView) row
.findViewById(R.id.textView1);
ImageView titleImageView = (ImageView) row
.findViewById(R.id.imageView1);
titleTextView.setText(Slidelist[position]);
titleImageView.setImageResource(images[position]);

return row;
}

}

}

错误日志: http://pastebin.com/fft3Rkes

最佳答案

您的 XML 可能不正确,请确保使用此 <android.support.v4.widget.DrawerLayout>

关于Android 自定义列表滑动菜单崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28481812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com