程序没有响应,我运行它没有编译时错误
有关更多信息,请查看以下链接
https://www.youtube.com/watch?v=rs4LW3GxOgE
public class MainActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
ListView mListView;
private ActionBarDrawerToggle toogle;
private custome_adapter adp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adp = new custome_adapter(this);
mListView.setAdapter(adp);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawerlayout);
mListView = (ListView)findViewById(R.id.list);
toogle = new ActionBarDrawerToggle(this,mDrawerLayout,R.string.open,R.string.close){
@Override
public void onDrawerOpened(View drawerView) {
Toast.makeText(MainActivity.this,"opening the Scroll",Toast.LENGTH_SHORT).show();
}
@Override
public void onDrawerClosed(View drawerView) {
Toast.makeText(MainActivity.this,"closing the scroll",Toast.LENGTH_SHORT).show();
}
};
mDrawerLayout.setDrawerListener(toogle);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
toogle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
toogle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(toogle.onOptionsItemSelected(item))
{
return true;
}
return super.onOptionsItemSelected(item);
}
}
class custome_adapter extends BaseAdapter
{
private Context context;
String[] week;
int[] images = {
R.drawable.a,
R.drawable.b,
R.drawable.c,
R.drawable.d,
R.drawable.e
};
public custome_adapter(Context context)
{
this.context = context;
week= context.getResources().getStringArray(R.array.week);
}
@Override
public int getCount() {
return week.length;
}
@Override
public Object getItem(int position) {
return week[position];
}
@Override
public long getItemId(int position) {
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.custome_row, parent, false);
}
else{
row = convertView;
}
ImageView imageView = (ImageView)row.findViewById(R.id.imageView);
TextView textView = (TextView)row.findViewById(R.id.textView);
imageView.setImageResource(images[position]);
textView.setText(week[position]);
return row;
}
}
答案 0 :(得分:0)
如果你想要一个没有出汗的炫酷导航抽屉,Android Studio里面有一个模板,你只需要用导航抽屉启动项目, 来实现这一点以下内容:
1. 点击文件
2.Then New>新项目
3.然后点击下一步,直到您 向活动添加活动