如何在与应用程序相同的程序中创建小部件?
就像如何为具有相同功能的应用程序创建一个小部件?
这是活动文件:
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();
}
}
});
}
}
我不想通过小部件进行更新。我只是希望小部件与应用程序完全相同。