2016-07-26 7 views
0

アクティビティでうまくいったコードとクラスをコピーしました。しかし、断片では、それは動作しません。アプリクラッシュはありませんが、リストは私のディスプレイに表示されません。 私のデータベースはすでにチェックされており、正常に機能しました。私のリストには何も表示されません。私を助けてください。以下は私のコードです。私のカスタマイズしたリストビューはフラグメント内では機能しません

ListFragment.java

public class ListFragment extends android.support.v4.app.Fragment { 

DBHelper mydb; 
SQLiteDatabase db; 

Intent retent; 
private int amount; 
private String date; 
private String time; 
private String use; 
private ListView useList; 
private ArrayList<history> histories; 
private historyAdapter adapter; 
private String checker; 
private TextView upperBalance; 

private int position=4; 
private int onClickPosition; 
private int itemcount; 
private int amt=0; 

public boolean bottomViewActivate = false; 
public boolean monthlyActivate = true; 

private int bottomViewId =0; 
private TextView Arvitor; 
private FrameLayout frameArvitor; 
private ArrayList<history> historiesBackup; 

private int CurrentYearMonthInt=0; 
private int CurrentAddBalance=0; 
public Calendar c = Calendar.getInstance(); 
public SimpleDateFormat intform = new SimpleDateFormat("yyMM"); 
public SimpleDateFormat yearform = new SimpleDateFormat("yyyy"); 
public SimpleDateFormat monthform = new SimpleDateFormat("MM"); 
public SimpleDateFormat yearf = new SimpleDateFormat("yy"); 
int year = Integer.parseInt(yearform.format(c.getTime())); 
int month = Integer.parseInt(monthform.format(c.getTime())); 

public ListFragment() { 

} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.fragment_page2, container, false); 
    year = Integer.parseInt(yearform.format(c.getTime())); 
    month = Integer.parseInt(monthform.format(c.getTime())); 
    CurrentYearMonthInt=Integer.parseInt(intform.format(c.getTime())); 
    mydb = new DBHelper(getActivity()); 

    upperBalance = (TextView)rootView.findViewById(R.id.ListUpView); 
    if(mydb.numberOfRows()!=0) { 
     upperBalance.setText(" Current Balance : "+mydb.getRecentBalance()+"won"); 
    }else { 
     upperBalance.setText(" Balance : 0won"); 
    } 

    useList=(ListView) rootView.findViewById(R.id.listView); 
    histories = new ArrayList<history>(); 
    adapter = new historyAdapter(getActivity(), R.layout.listsublayout, histories); 
    useList.setAdapter(adapter); 
    getActivity().registerForContextMenu(useList); 
    histories=mydb.getAllUseList(bottomViewId,bottomViewActivate,monthlyActivate,CurrentYearMonthInt); 
    itemcount=mydb.numberOfRows(); 
    adapter.notifyDataSetChanged(); 

    return rootView; 
    } 
} 

答えて

0

私は、この問題を解決しました。

しかし、私はこのソリューションが動作する理由を理解できません。 とにかく、私はこの問題を誰が同じ問題で苦しんでいるかについてどのように解決したかを提示します。

Iは

履歴= mydb.getAllUseList(bottomViewId、bottomViewActivate、monthlyActivate、CurrentYearMonthInt)に変更。

histories.addAll(mydb.getAllUseList(bottomViewId、bottomViewActivate、monthlyActivate、CurrentYearMonthInt))に

この解決策が私の質問に答える理由を知っている人は、誰でも。

関連する問題