我想,如果我點擊'Leerlingenraad'的列表視圖,他打開Leerlingenraad.xml類的Leerlingenraad類,如果我點擊聯繫人,他打開類與contact.xml聯繫我已經找到這很多話題,但它不會工作。有人知道我的腳本中出了什麼問題嗎?請不要評價。Android listview onclicklistener活動
Myclass.java:
package com.example.myapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem.*;
import android.view.MenuItem;
import android.view.MenuInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import android.text.Editable;
import android.widget.AdapterView.OnItemClickListener;
import android.text.TextWatcher;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.view.ViewGroup;
import android.widget.Toast;
public class Myclass extends Activity {
// List view
private ListView lv;
// Listview Adapter
ArrayAdapter<String> adapter;
// Search EditText
EditText inputSearch;
// ArrayList for Listview
ArrayList<HashMap<String, String>> onderneming;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myclass);
String onderneming[] = {"Leerlingenraad", "Medezeggenschapsraad", "3", "4", "5", "6", "Contact"};
lv = (ListView) findViewById(R.id.list_view);
inputSearch = (EditText) findViewById(R.id.inputSearch);
// Adding items to listview
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, onderneming);
lv.setAdapter(adapter);
/**
* Enabling Search Filter
* */
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
Ondernemerschap.this.adapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
final int position, long id) {
String main = lv.getSelectedItem().toString();
}
});
}
private ListView getListView() {
return null;
}
}
myclass.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/pallasrood"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/android" />
<EditText android:id="@+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"android:hint="Zoek de onderneming.."
android:inputType="textVisiblePassword"/>
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="@+id/inputSearch"
android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent" >
</ListView>
</RelativeLayout>
AndroidManifest.xml中
<activity android:name=".Leerlingenraad"
android:label="Pallasapp">
</activity>
聽起來你需要使用活動。爲'Leerlingenraad'和'Contact'創建一個新的活動,並使用'Intent's和'startActivity()'來改變這些活動。 – RogueBaneling 2014-12-03 16:08:40
你應該看看[這個](http://developer.android.com/training/index.html),這會幫助你很多。特別是[開始另一個活動](http://developer.android.com/training/basics/firstapp/starting-activity.html)一章。 – James 2014-12-03 16:14:03
你可以粘貼你的列表視圖屏幕截圖,讓我們明白你在問什麼 – Psypher 2014-12-03 16:22:16