package com.darkweb.android.amityaaroh.HomeActivity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.darkweb.android.amityaaroh.R;
public class events extends Fragment {
ListView listView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.events, container, false);
return rootView;
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.events);
initializeListView();
}
private void initializeListView() {
listView = (ListView)getView().findViewById(R.id.listview);
final String[] items = {"One", "Two", "Three", "Four", "Five", "Six", "Seven"};
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.list_item, R.id.textView2, items);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = items[position];
Toast.makeText(events.this.getActivity(), item+" is clicked", Toast.LENGTH_LONG).show();
}
});
}
}
錯誤:我們可以把片段與appcomactivity 錯誤:(29,9)錯誤:無法找到符號方法的setContentView(int)的 錯誤:執行失敗的任務 ':應用程序:compileDebugJavaWithJavac'。Android的碎片與Appcompactivity
Compilation failed; see the compiler error output for details.
刪除onCreate() – Akash
中的setContentView方法在事件活動時應用程序未運行!如果我刪除setcontentview –
刪除創建方法並調用你的initializeListView();方法在OnResume方法 – ashish