【发布时间】:2014-08-28 04:24:55
【问题描述】:
我在我的activity_main 上创建了一个文本按钮,单击该按钮时我想打开一个名为gallery 的新xml。我为此创建了一个 xml 和类。当我点击按钮时,它不会带我去任何地方。
activity_main.xml
<Button android:text="@string/Gallery"
android:id="@+id/Button01"
android:layout_width="200dp"
android:textSize="28sp"
android:background="@color/black"
android:textColor="@color/pink"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
</Button>
安卓清单
<activity android:name=".Gallery"
android:label="@string/app_name" />
两个.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.widget.Button;
public class Two extends Activity {
Button Button01;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
Button next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Gallery.class);
startActivityForResult(myIntent, 0);
}
});
}
}
gallery.java
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class Gallery extends FragmentActivity {
ViewPager mPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
mPager = (ViewPager) findViewById(R.id.frame);
mPager.setOffscreenPageLimit(1);
mPager.setAdapter(new EndLessAdapter(this, mImageArray));
// Look up the AdView as a resource and load a request.
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
private int[] mImageArray = {R.drawable.y1,};
}
【问题讨论】:
标签: java android class android-studio