0
請問我有問題。我打算在點擊listview上的項目時顯示敬酒。但是這些項目並未顯示即使點擊它們的響應。 下面的代碼:listfragment中的listview中的項目沒有響應
package com.ejikedozie.pcsolutions;
import android.app.Notification;
import android.app.NotificationManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.support.v7.app.NotificationCompat;
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.ejikedozie.pcsolutions.R;
public class OneFragment extends ListFragment implements AdapterView.OnItemClickListener {
public OneFragment() {}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_one, container, false);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.Planets, android.R.layout.simple_list_item_1);
setListAdapter(adapter);
getListView().setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Toast.makeText(getActivity(), "Item: " + position, Toast.LENGTH_SHORT).show();
switch (position){
case 1:
Toast.makeText(getActivity(), "Item: ", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
}
任何幫助,將不勝感激。謝謝。
Post ur ListFragment class too –