我正在尝试使用 Android 的 master-detail 流程来开发 master-child 页面概念,但在执行方面,该设计很容易受到性能不佳的批评。你能告诉我一些指导方针来提高性能besude加载位图选项?
以下是我的片段代码
import java.util.ArrayList;
import java.util.List;
import com.aaa.demo.asynctask.ResubmitOrder;
import com.aaa.demo.util.*;
import android.os.Bundle;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.app.*;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class MoreActivity extends Fragment
{
private Bundle parameter;
private FileManager fileMan;
private SalesOrderRetransmitDbAdapter soDbRetransmitHelper;
public class RecordAdapter extends BaseAdapter
{
Context context;
private List<String> data;
RecordAdapter(List<String> data, Context context)
{
this.data = data;
this.context = context;
}
public int getCount()
{
return data.size();
}
public Object getItem(int position)
{
return data.get(position);
}
public long getItemId(int position)
{
return position;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.more_item, null);
}
final String item = data.get(position);
ImageView imageView = (ImageView) v.findViewById(R.id.more_item);
imageView.setImageDrawable(FileUtil.readImage(context, item + ".png"));
imageView.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(item.equalsIgnoreCase("more_update"))
{
((ActivityInTab) getActivity()).switchToFragment(new UpdateContentActivity());
Runtime.getRuntime().gc();
}
else if(item.equalsIgnoreCase("more_building"))
{
parameter = new Bundle();
parameter.putString("salesid", MainActivity.useridStatic);
Fragment s = new EOrderSystemBuildList();
s.setArguments(parameter);
((ActivityInTab) getActivity()).switchToFragment(s);
}
else if(item.equalsIgnoreCase("more_qc"))
{
parameter = new Bundle();
parameter.putString("salesid", MainActivity.useridStatic);
Fragment s = new EOrderList();
s.setArguments(parameter);
((ActivityInTab) getActivity()).switchToFragment(s);
}
else if(item.equalsIgnoreCase("more_password"))
{
parameter = new Bundle();
parameter.putString("salesid", MainActivity.useridStatic );
Fragment s = new EOrderChangePassword();
s.setArguments(parameter);
((ActivityInTab) getActivity()).switchToFragment(s);
}
else if(item.equalsIgnoreCase("more_logout"))
{
getActivity().finish();
Runtime.getRuntime().gc();
}
else if(item.equalsIgnoreCase("more_resubmit"))
{
ResubmitOrder resubmit = new ResubmitOrder(getActivity());
resubmit.execute(MainActivity.useridStatic + "|" + MainActivity.isFollowup);
}
}
});
return v;
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
final View v = inflater.inflate(R.layout.activity_more, container, false);
ArrayList<String> records = new ArrayList<String>();
records.add("more_building");
records.add("more_qc");
records.add("more_password");
records.add("more_logout");
records.add("more_update");
fileMan = new FileManager();
int count = fileMan.loadRecordRecursiveCount("SV_recordings","sales_recording");
Log.d("file count " , String.valueOf(count));
soDbRetransmitHelper= new SalesOrderRetransmitDbAdapter(getActivity());
soDbRetransmitHelper.open();
Cursor bu = soDbRetransmitHelper.fetchAllUnSubmitOrder(MainActivity.useridStatic);
bu.moveToFirst();
int data = bu.getCount();
Log.d("data count " , String.valueOf(data));
if(count > 0 || data > 0 ){
records.add("more_resubmit");
}
bu.close();
soDbRetransmitHelper.close();
GridView gridView = (GridView) v.findViewById(R.id.more_gridview);
gridView.setAdapter(new RecordAdapter(records, getActivity()));
return v;
}
}