0

私はこの問題を解決するために何日も探し回っていましたが、ここでいくつかの質問を見てきました。そのうちのいくつかは解決されましたが、私の状況は他の状況とは少し異なるため、実際にはどれも役に立ちませんでした.

アプリの一部で、アプリの他の部分で開始されたすべてのキャンペーンの履歴を表示します。そのために、履歴アクティビティ内でリストビューを使用しています。ここにアクティビティのコードがあります

HistoryList.java

public class HistoryList extends Activity {

Campaign_Db myCamp = new Campaign_Db(HistoryList.this);
Date_calc myDate = new Date_calc(HistoryList.this);
graphCreate mygraph = new graphCreate(HistoryList.this);

 ListView historylist;
 SimpleCursorAdapter cursorAdapter;
 Cursor cursor = null;
 String picadd;
 ImageView pic;
 ArrayList<Integer> array_cap = new ArrayList<Integer>();
 Integer[] arr_cap;
 int passing_id;
 String passing_date,passing_startdate;
 GraphicalView newgraph;

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.historylist);


    historylist = (ListView) findViewById(R.id.historylistview);

    myCamp.open();
    cursor = myCamp.gethistory();
    if(cursor !=null && cursor.moveToFirst()){
    int rowenddate = cursor.getColumnIndex(Campaign_Db.KEY_ROWID);
    int rowstartdate = cursor.getColumnIndex(Campaign_Db.KEY_START);

    String camp_id = cursor.getString(rowenddate);
    passing_id = Integer.valueOf(camp_id);
    passing_date = cursor.getString(rowstartdate);
    }
    getdata();
    newgraph = mygraph.startgraph(arr_cap,this);



    HistoryAdapter histAdap = new HistoryAdapter(HistoryList.this,cursor,R.layout.historyrow,arr_cap, newgraph);


    historylist.setAdapter(histAdap);
}


private void getdata() {



String dt = myDate.Calc(passing_date);

int d = Integer.valueOf(dt);
    try {

        array_cap = myCamp.historygarphs(d,passing_id,passing_date);

    } catch (ParseException e) {

        e.printStackTrace();
    }
arr_cap = array_cap.toArray(new Integer[array_cap.size()]);



}


}

そのアクティビティで、リストビューをカスタム アダプターに設定し、使用するカーソルと使用する AChartEngine グラフを渡します。グラフとカーソル データはすべてテストされ、ログに記録されているため、問題はありません。カスタムアダプターのコードは次のとおりです

HistoryAdapter.java

 public class HistoryAdapter extends CursorAdapter {

private Context context;
private int layout;
private Integer[] arr_cap;
String picadd;
GraphicalView newgraph;


@SuppressWarnings("deprecation")
public HistoryAdapter(Context context, Cursor c, int layout, Integer[] arr, GraphicalView grp) {
    super(context, c);
    this.arr_cap= arr;
    this.context = context;
    this.layout = layout;
    this.newgraph = grp;

}

Campaign_Db myCamp = new Campaign_Db(context);

Date_calc myDate = new Date_calc(context);

@Override
public void bindView(View view, Context context, Cursor cursor) {
    int rowaddress = cursor.getColumnIndex(Campaign_Db.KEY_PIC);
    int rowenddate = cursor.getColumnIndex(Campaign_Db.KEY_ROWID);
    int rowstartdate = cursor.getColumnIndex(Campaign_Db.KEY_START);
    int rowcampname = cursor.getColumnIndex(Campaign_Db.KEY_NAME);

    ImageView pic = (ImageView) view.findViewById(R.id.history_picture);
    TextView enddate = (TextView) view.findViewById(R.id.history_enddate);
    TextView startdate = (TextView) view.findViewById(R.id.history_startdate);
    TextView campaign_name = (TextView) view.findViewById(R.id.history_campaignname);
    LinearLayout lay = (LinearLayout) view.findViewById(R.id.historychart); 





    lay.addView(newgraph, new LayoutParams(220, 80));



    if (cursor != null && cursor.moveToFirst()){
    picadd = cursor.getString(rowaddress);
    enddate.setText(cursor.getString(rowenddate));
    startdate.setText(cursor.getString(rowstartdate));
    campaign_name.setText(cursor.getString(rowcampname));
    }


    File imgFile = new  File(picadd);
    if(imgFile.exists()){



        Bitmap bmp = BitmapFactory.decodeFile(picadd);
        Bitmap reducedbmp = Bitmap.createScaledBitmap(bmp, 100, 100, true);
        Bitmap rightsidebmp = getrightside(reducedbmp);
        Bitmap finalbmp = getRoundedCornerBitmap(rightsidebmp, 50);

        pic.setImageBitmap(finalbmp);


    }

}

@Override
public View newView(Context context, Cursor cursor,ViewGroup parent ) {
    final LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(layout,null,false);
    bindView(v, context, cursor);
    return v;
}

public Bitmap getrightside(Bitmap bit){
    Bitmap bmp = bit;
    File f = new File(picadd);
    ExifInterface exif = null;
    try {
        exif = new ExifInterface(f.getPath());
    } catch (IOException e) {

        e.printStackTrace();
    }
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

    int angle = 0;

    if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
        angle = 90;
    } 
    else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
        angle = 180;
    } 
    else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
        angle = 270;
    }

    Matrix mat = new Matrix();
    mat.postRotate(angle);
    Bitmap correctBmp = Bitmap.createBitmap(bit , 0, 0, bmp.getWidth(), bmp.getHeight(), mat, true);
    return correctBmp;
}

public Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
            .getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
  }
 }

この問題は、別のアクティビティで既に行った方法で、chartengine グラフを相対レイアウトに追加しようとすると発生します。

この行がコメント化されている場合、残りのコードは完全に実行されます。

lay.addView(newgraph, new LayoutParams(220, 80));

私が読んでいるものから、私が得るエラー

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

子を使用して、既に親がある場合に別の親を与えようとすると発生しますが、この場合、子の新しいグラフはカスタム アダプター クラスで初期化されたばかりで、getparent() が使用されると null が返されます。 .

誰かがこれを理解するのを助けることができれば素晴らしいでしょう、事前に感謝します.

4

0 に答える 0