这个简单的代码!
package itawfik.com.wifi;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
/**
* Created by Emin01 on 03/09/2016.
*/
public class ListWifi extends AppCompatActivity {
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listwifi);
list = (ListView) findViewById(R.id.listId);
MyTawfik.setUpListView(list);
String[] values = new String[]{"Android List View",
"Adapter implementation",
"Simple List View In Android",
"Create List View Android",
"Android Example",
"List View Source Code",
"List View Array Adapter",
"Android Example List View"
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item index
int itemPosition = position;
// ListView Clicked item value
String itemValue = (String) list.getItemAtPosition(position);
// Show Alert
Toast.makeText(getApplicationContext(),
"Position :" + itemPosition + " ListItem : " + itemValue, Toast.LENGTH_LONG)
.show();
}
});
}
}
这是我使用它的地方!
public void listConacted() {
Intent intent = new Intent(this, ListWifi.class);
startActivity(intent);
}
致命的例外:主要 java.lang.IllegalStateException:找不到方法 listConacted(View)在父或祖先上下文中为android:onClick 在视图类上定义的属性 android.support.v7.widget.AppCompatTextView,带有id&#39; textView&#39; 在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327) 在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284) 在android.view.View.performClick(View.java:4204) 在android.view.View $ PerformClick.run(View.java:17355) 在android.os.Handler.handleCallback(Handler.java:725) 在android.os.Handler.dispatchMessage(Handler.java:92) 在android.os.Looper.loop(Looper.java:152) 在android.app.ActivityThread.main(ActivityThread.java:5132) at java.lang.reflect.Method.invokeNative(Native Method) 在java.lang.reflect.Method.invoke(Method.java:511) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 在dalvik.system.NativeStart.main(本地方法)
答案 0 :(得分:0)
找不到方法listConacted()。 listConacted(查看v)
答案 1 :(得分:0)
public void listConacted() - &gt; public void listConacted(View view); - Shaishav