关注本指南Sliding Menu using Navdrawer
一切顺利,直到我在android studio中的getSystemService和getCounterVisability行上出错,
我的适配器类如下包com.jembe.locals.adapter;
import com.jembe.locals.R;
import com.jembe.locals.model.NavDrawerItem;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/**
* Created by mine on 12/03/14.
*/
public class NavDrawerListAdapter extends BaseAdapter {
private Context context;
private ArrayList<NavDrawerItem> navDrawerItems;
public NavDrawerListAdapter(Context context, ArrayList<NavDrawerItem> navDrawerItems){
this.context = context;
this.navDrawerItems = navDrawerItems;
}
@Override
public int getCount(){
return navDrawerItems.size();
}
@Override
public Object getItem(int position){
return navDrawerItems.get(position);
}
@Override
public long getItemId(int position){
return position;
}
@Override
public View getView(int position,View convertView, ViewGroup parent){
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater)
context.getSytemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.drawer_list_item, null);
}
ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
TextView txtCount = (TextView) convertView.findViewById(R.id.counter);
imgIcon.setImageResource(navDrawerItems.get(position).getIcon());
txtTitle.setText(navDrawerItems.get(position).getTitle());
// displaying count
// check whether it set visible or not
if(navDrawerItems.get(position).getCounterVisibility()){
txtCount.setText(navDrawerItems.get(position).getCount());
}else{
// hide the counter view
txtCount.setVisibility(View.GONE);
}
return convertView;
}
}
有谁能指出我的问题是什么?
出于信息目的,我使用android studio,通过sdk manager安装所有sdks和支持类
Gradle tasks [:locals:assembleDebug]任务执行失败 &#39;:当地人:compileDebugJava&#39;
编译失败;请参阅编译器错误输出以获取详细信C:\用户\矿山\ AndroidStudioProjects \ LocalsAware \当地人的\ src \主\ java中的\ com \ jembe \当地人\适配器\ NavDrawerListAdapter.java 错误:找不到符号方法getSytemService(String)错误:不能 找到符号方法getCounterVisibility()
我也发布了我的适配器类和我的主要活动类。
package com.jembe.locals;
import android.app.Activity;
import android.app.ActionBar;
import android.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.os.Build;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
public class MainActivity extends Activity {
private String[] mTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitles = getResources().getStringArray(R.array.nav_drawer_items);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.drawer_layout, new PlaceholderFragment())
.commit();
}
}
@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 boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
这是我的navDrawerItem.java
package com.jembe.locals.model;
/**
* Created by mine on 12/03/14.
*/
public class NavDrawerItem {
private String title;
private int icon;
private String count = "0";
// boolean to set visbility of the counter
private boolean isCounterVisble = false;
public NavDrawerItem(){}
public NavDrawerItem(String title, int icon){
this.title = title;
this.icon = icon;
}
public NavDrawerItem(String title,int icon,boolean isCounterVisble){
this.title = title;
this.icon = icon;
this.isCounterVisble = isCounterVisble;
this.count = count;
}
public String getTitle(){
return this.title;
}
public int getIcon(){
return this.icon;
}
public String getCount(){
return this.count;
}
public boolean getCouterVisibility(){
return this.isCounterVisble;
}
public void setTitle(String title) {
this.title = title;
}
public void setIcon(int icon) {
this.icon = icon;
}
public void setCount(String count) {
this.count = count;
}
public void setCounterVisble(boolean isCounterVisble) {
this.isCounterVisble = isCounterVisble;
}
}