清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="qu.clock">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity2">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
mainclass:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ImageView ClockButton;
private LinearLayout linearLayout;
private TextView[] textViews;
private int hours;
private int minutes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViews=new TextView[20];
linearLayout=(LinearLayout)findViewById(R.id.LinearLayout1);
ClockButton=(ImageView)findViewById(R.id.ClockIconButton);
ClockButton.setOnClickListener(this);
}
public void onChangeContentView()
{
Intent intent = new Intent(this, MainActivity2.class);
startActivityForResult(intent,2);
}
@Override
public void onClick(View v) {
onChangeContentView();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(getApplicationContext(),"test",Toast.LENGTH_SHORT).show();//test
hours=Integer.parseInt(data.getStringExtra("H"));
minutes=Integer.parseInt(data.getStringExtra("M"));
for(int i=0;i<textViews.length;i++)
{
if(textViews[i]==null)
{
textViews[i].setText(hours+" : "+minutes);
linearLayout.addView(textViews[i]);
break;
}
}
}
}
子类:
public class MainActivity2 extends AppCompatActivity implements View.OnClickListener {
private ImageView OkButton;
private TimePicker timePicker;
private int hours;
private int minutes;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
OkButton = (ImageView) findViewById(R.id.OkIcon);
OkButton.setOnClickListener(this);
timePicker = (TimePicker) findViewById(R.id.TimePicker1);
}
@Override
public void onClick(View v) {
hours = timePicker.getCurrentHour();
minutes = timePicker.getCurrentMinute();
Intent intent = new Intent();
intent.putExtra("H", hours);
intent.putExtra("M", minutes);
setResult(RESULT_OK,intent);
finish();
}
}
我仍然坚持要解决这些问题 我昨天已经让它知道了 但他们没有帮助我 我该怎么办?
我还尝试将android:launchmode=""
和android:nohistory="false"
放入清单。