私はプログラミングを始めたばかりで、週末のちょっとした趣味です。インタラクティブなカレンダーのようなアプリを作成したいのですが、基本的にはこのように機能します..
メインのアクティビティには、日付をタップできるカレンダーが表示され、新しいアクティビティが開始されます。この新しいアクティビティでは、アイテムのカテゴリを選択できます。カテゴリを選択すると、カレンダーの日付に ImageButton が追加されます。ボタンを配置したら、それをタップして追加情報 (アラーム、場所、詳細など) を設定できます。
すべてのカレンダー レイアウト、さまざまなアクティビティへのボタン、およびカレンダー日付の ImageButton の動的な追加を行うことはできましたが、ユーザーが追加したデータ (ImageButton) を保存する方法については行き詰まりました。'アクティビティ B (例: スポーツの日付) でボタン 1 をクリックすると、アクティビティ A (カレンダー) レイアウトに野球の動的な画像ボタンが作成されるため、そのデータを永続的に保存するにはどうすればよいですか (ユーザーが削除できます)。
ここ数日、Onpause、onSaveinstancestate、onConfiguration、SQL、fragments、およびデータベースを読んでいます。しかし、別のアクティビティから作成されたアクティビティ オブジェクトに適用することは言うまでもなく、これを適用する方法について頭も尻尾も作ることができません。洞察をいただければ幸いです。
動的ボタンを作成するボタンを使用したアクティビティの私のコード:
package org.iimed.www;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import org.iimed.www.Sundayopen;
import android.widget.RelativeLayout;
import android.widget.TableLayout.LayoutParams;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
public class Penicillins extends Activity implements OnClickListener {
ImageButton addmed,ab;
RelativeLayout ll;
public void onCreate(Bundle SavedInstanceState){
super.onCreate(SavedInstanceState);
setContentView(R.layout.penicillin);
addmed =( ImageButton)findViewById(R.id.addmed);
addmed.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()){
case R.id.addmed:
setContentView(R.layout.sundayopen);
ll =(RelativeLayout) findViewById(R.id.sundayopen);
android.widget.LinearLayout.LayoutParams b = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
int i = 0;
ab = new ImageButton(this);
ab.setImageResource(R.drawable.adaba);
ab.setBackgroundColor(Color.TRANSPARENT);
ab.setLayoutParams(b);
ab.setId(i) ;
ab.getId();
ab.setTag(1);
ll.addView(ab);
}
}
}
My code for the activity the button appears in:
package org.iimed.www;
import java.util.ArrayList;
import android.R.string;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.view.View.OnClickListener;
public class Sundayopen extends Activity implements OnClickListener {
public static final Integer [] aba = {R.id.aba};
ImageButton ab;
public void onCreate(Bundle SavedInstanceState) {
super.onCreate(SavedInstanceState);
setContentView(R.layout.sundayopen);
ImageButton hb1 = (ImageButton) findViewById(R.id.homebutton1);
RelativeLayout ll =(RelativeLayout) findViewById(R.id.sundayopen);
ImageButton sbc = (ImageButton) findViewById(R.id.satlidopen);
ImageButton abb = (ImageButton) findViewById(R.id.abbutton);
sbc.setOnClickListener(this);
hb1.setOnClickListener(this);
abb.setOnClickListener(this);
}
public void onClick(View v){
switch (v.getId()) {
case R.id.homebutton1:
startActivity(new Intent(this, MainActivity.class));
break;
case R.id.satlidopen:
MediaPlayer media = MediaPlayer.create(Sundayopen.this, R.raw.openlid);
media.start();
startActivity(new Intent(this,Iimedja.class));
break;
case R.id.abbutton:
startActivity(new Intent(this, ImageTextListViewActivity.class));
}
}
}