我的客户要求是创建一个有三个按钮的页面,点击该按钮,它必须到我网站的指定网址,如果我们选择登录,它必须在我的网络应用程序中获得该特定页面。我我是一个非常新的android和一些我是如何创建的,但他希望所有这些都在一个盒子里。我在很多网站上搜索过自定义对话框,bla bla bla ...但我没有任何解决方案。他给了我一些网站供参考,布局必须像那样..那个网址是 在这个网址中https://play.google.com/store/apps/details?id=com.jwaala.mobile.redwoodcuorg&hl=en他希望布局像第一次屏幕截图。
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button login;
private Button register;
private Button ContactUs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login = (Button)findViewById(R.id.button1);
register = (Button)findViewById(R.id.button2);
ContactUs= (Button)findViewById(R.id.button3);
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Uri uri = Uri.parse("some url");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
public void onClick1(View arg0) {
// TODO Auto-generated method stub
}
});
register.setOnClickListener(new OnClickListener() {
public void onClick2(View v) {
// TODO Auto-generated method stub
Uri uri = Uri.parse("some url");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
ContactUs.setOnClickListener(new OnClickListener() {
public void onClick1(View v) {
// TODO Auto-generated method stub
Uri uri = Uri.parse("some url");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
}
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
android:weightSum="6">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3.5" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="60dp"
android:src="@drawable/tasknbilllogo" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="260dp"
android:background="#ffff66"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:orientation="vertical"
android:weightSum="3" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffa64c"
android:text="-----"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:textColor="#4c4cff" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:background="#ffa64c"
android:textColor="#4c4cff"
android:text="Register" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:background="#ffa64c"
android:textColor="#4c4cff"
android:text="------" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
使用listview:
<强> .XML 强>
<ListView
android:id="@+id/list"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</ListView>
<强>活动强>
private ListView listView;
在您的onCreate()
方法中:
listView = (ListView) findViewById(R.id.list);
数组:
// Defined Array values to show in ListView
String[] values = new String[] { "Login",
"Register",
"Contact Us"};
新适配器:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
分配适配器:
// Assign adapter to ListView
listView.setAdapter(adapter);
和onItemClickListener()
:
// ListView Item Click Listener
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
switch(position){
case 1:
Uri uri = Uri.parse("https://app.tasknbill.net/login.aspx");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
case 2:
uri = Uri.parse("https://app.tasknbill.net/register.aspx");
intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
case 3:
uri = Uri.parse("https://tasknbill.net/#contact");
intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
}
}
});