相关疑难解决方法(0)

导航抽屉项目未注册单击事件

我正在努力让导航抽屉项目注册并开始和意图进行新的活动.抽屉打开正常并正确显示但是当我点击列表中的项目时没有任何反应.这是我从谷歌教程中获取的代码.

mTitle = mDrawerTitle = getTitle();
           mTitles = getResources().getStringArray(R.array.menu_items);
           mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
           mDrawerList = (ListView) findViewById(R.id.left_drawer);

           // set a custom shadow that overlays the main content when the drawer opens
           mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
           // set up the drawer's list view with items and click listener
           mDrawerList.setAdapter(new ArrayAdapter<String>(this,
                   R.layout.drawer_list_item, mTitles));
           mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

           // enable ActionBar app icon to behave as action to toggle nav drawer
           getActionBar().setDisplayHomeAsUpEnabled(true);
           getActionBar().setHomeButtonEnabled(true);

           // ActionBarDrawerToggle ties together the the proper interactions
           // between the sliding drawer and …
Run Code Online (Sandbox Code Playgroud)

android onclick android-listview navigation-drawer

20
推荐指数
2
解决办法
2万
查看次数

Android列表视图setOnItemClickListener无法正常工作

我想在列表视图中隐藏编辑文本和按钮字段,并在单击原始视图时显示列表视图中特定原始视图的编辑文本和按钮.所以我尝试在布局xml中将高度设置为0然后设置它当用户点击原始文件时,为了一些其他值,但它不起作用我认为我的列表视图点击事件不起作用.在我有列表视图的Android布局中,还有图像视图作为按钮,编辑文本字段和列表视图.如下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainPortal" >

<ListView
    android:id="@+id/employeeListView"
    android:layout_width="650dp"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="25dp"
    android:clickable="true">
</ListView>

<EditText
    android:id="@+id/empPin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/iv_start_journey_btn"
    android:layout_marginBottom="56dp"
    android:layout_marginRight="17dp"
    android:layout_toLeftOf="@+id/employeeListView"
    android:ems="10"
    android:inputType="number"
    android:hint="@string/add_emp_pin_hint" >

    <requestFocus />
</EditText>

<ImageView
    android:id="@+id/iv_start_journey_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/employeeListView"
    android:layout_alignRight="@+id/empPin"
    android:layout_marginBottom="84dp"
    android:onClick="startJourney"
    android:src="@drawable/start" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我在列表视图中使用了以下自定义布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/emp_avatar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="18dp"
    android:adjustViewBounds="true"
    android:maxHeight="80dp"
    android:maxWidth="80dp"
    android:src="@drawable/person" />

<TextView
    android:id="@+id/emp_number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/emp_avatar"
    android:layout_toRightOf="@+id/emp_avatar"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText …
Run Code Online (Sandbox Code Playgroud)

android android-emulator android-layout android-listview

5
推荐指数
1
解决办法
3万
查看次数

ListView setOnItemClickListener无法在自定义列表视图中工作

我有一个列表视图,每行有两个文本视图和一个编辑文本,列表视图setOnItemClickListener()不起作用.

这里是我的Java代码.

public class CreateChallan extends Activity {


ListView lstCreate;

String[] strmainItemCode;
String[] strItem;
String[] strQuantity;
Context context=this;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.createchallan);
    lstCreate= (ListView) findViewById(R.id.createlist);
    lstCreate.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);

    strmainItemCode= new String[]{"555551","255555","355555","455555","555555"};

    strItem =new String[]{"A","B","C","D","F"};

    strQuantity =new String[]{"100","200","30","400","500"};

    CreateAdapter adapter= new CreateAdapter(this, strmainItemCode, strItem, s trQuantity);

    lstCreate.setAdapter(adapter);

    lstCreate.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position1, long id) {
            // TODO Auto-generated method stub

            Toast.makeText(context, "Position",   Toast.LENGTH_LONG).show();

        }
    });
}







// Create List Adapter

class CreateAdapter …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-listview

5
推荐指数
2
解决办法
2万
查看次数