アプリと同じプログラムでウィジェットを作成する方法は?
同じ機能を実行するアプリのウィジェットを作成する方法と同じように?
これはアクティビティ ファイルです。
public class SmsActivity extends Activity {
Button b1;
EditText a;
String b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
a=(EditText)findViewById(R.id.e2);
a.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
b=a.getText().toString();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,int count) {
// TODO Auto-generated method stub
}
});
b1= (Button) findViewById(R.id.b1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, b);
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS failed, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
}
ウィジェットによる更新はしたくありません。ウィジェットがアプリとまったく同じことをしたいだけです。