5
這似乎是一個常見問題,通常通過添加正確的導入來解決。但在我看來,這似乎並沒有解決任何問題。我對Android編程相當陌生,所以請耐心等待我的愚蠢錯誤(如果適用)。OnItemClickListener無法解析爲類型(在片段內)
我有以下導入和代碼,但Eclipse一直說AdapterView.onItemClickListener無法解析爲類型。任何幫助將非常感激。
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
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.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public static class MainApplicationFragment extends Fragment {
private ArrayAdapter<String> listAdapter;
public MainApplicationFragment() {
}
private void PopulateWorkorderList() throws IOException {
StorageAccess access = new StorageAccess();
listAdapter = new ArrayAdapter<String>(getActivity(), R.layout.workorder_list_row);
for (Workorder WO : access.GetAllWorkorders()) {
listAdapter.add(WO.getWorkorderNumber().toString());
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
try {
PopulateWorkorderList();
ListView mainListView = (ListView) getView().findViewById(R.id.workorderList);
mainListView.setAdapter(listAdapter);
mainListView.setOnItemClickListener(new AdapterView.onItemClickListener() {
public void onItemClick(AdapterView<> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
親愛的主人......就是這樣。感謝(!)並抱歉發佈這樣一個愚蠢的問題。 – Hetiwos
不客氣 – Blackbelt
OMG !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. - (張大嘴巴).. – Elltz