Android開発の初心者で、初めてのテストアプリケーションを開発しようとしています。 500文字を超える文字列を表示して検索を適用することに関するベストプラクティスの質問があります。Androidのベストプラクティスで500文字以上の文字列を表示して検索する
I持つ食品のカロリーの一覧については、以下のサンプル:
タイプ - ポーションサイズ - 200件のCAL - - 110件のCAL
鴨ロース100グラム(3.5オンス)
カニ新鮮あたり - 400件のCAL - 430件のCAL
牛肉(ロースト) - 300件のCAL - 280件のCAL
ビーフバーガーFローゼン - 320のCAL - 280件のCAL
チキン - 220件のCAL - 食品500種類以上のための200件のCAL
など.....。
次のことを実行するのが安全か、それともベストプラクティスですか?
public class FoodCal {
public String Type;
public String PortionSize;
public String PerGram;
public FoodCal(String type, String portionSize, String perGram) {
this.Type = type;
this.PortionSize = portionSize;
this.PerGram = perGram;
}
}
グローバルクラス:
public class Global {
public static ArrayList<FoodCal> GetFoodCalList() {
ArrayList<FoodCal> FoodCalList = new ArrayList<>();
FoodCalList.add(new FoodCal("Crab fresh","200 cals","110 cals"));
FoodCalList.add(new FoodCal("Duck roast","400 cals","430 cals"));
etc.......
return (FoodCalList);
}
}
FoodListAdapterクラス
class FoodListAdapter extends BaseAdapter {
ArrayList<SystemName> foodListLocal;
ArrayList<SystemName> fullFoodList;
FoodListAdapter() {
foodListLocal = Global.GetFoodCalList();
}
public void filter(String charText) {
fullFoodList = Global.GetFoodCalList();
foodListLocal.clear();
if (charText.length() == 0) {
foodListLocal = Global.GetFoodCalList();
} else {
for (FoodCal food : fullFoodList) {
if (food.Type.contains(charText)) {
foodListLocal.add(food);
}
}
}
//Notify UI
this.notifyDataSetChanged();
}
@Override
public int getCount() {
return foodListLocal.size();
}
@Override
public Object getItem(int position) {
return foodListLocal.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = getLayoutInflater();
View myView = mInflater.inflate(R.layout.food_view, null);
TextView txtFoodName = (TextView) myView.findViewById(R.id.txtFoodName);
TextView txtSize = (TextView) myView.findViewById(R.id.txtSize);
TextView txtPerGrams = (TextView) myView.findViewById(R.id.txtPerGrams);
FoodCal temp = foodListLocal.get(position);
txtFoodName.setText(temp.Type);
txtSize.setText(temp.PortionSize);
txtPerGrams.setText(temp.PerGram);
return myView;
}
}
私は、JSONファイルを使用する必要があります、それは良好な性能を持っているだろうか? Jsonの方が良い場合は、それを実行するためのコードまたはそのためのベストプラクティスを書いてください。
また、私のコードがより多くの強化が必要な場合は指定してください。
ありがとうございます。
大規模なデータを 'SQLite'データベースに格納し、' CursorAdapter'を使用してユーザーにリストを表示し、 'LIKE'選択で照会することでフィルターするのがベストです。 –