【发布时间】:2015-08-27 06:21:39
【问题描述】:
我正在使用安卓工作室。我正在尝试在 android studio 中使用 web 服务,但找不到任何教程或帮助代码在 android studio 中使用。在 Eclipse 中,GetText() 用于进行 POST 方法调用。我在 android studio 中使用什么而不是那种方法?谁能帮我发送一个从服务器获取数据的工作代码,并在android studio中使用POST和GET方法将请求发送到服务器。有没有其他替代方法可以在 android 中调用 Web 服务?
这是我的 xml 设计
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".HttpPostExample">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="vertical"
android:background="#FF9696">
<TextView android:id="@+id/content"
android:text="@string/op"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#995A5A">
</View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="20dp"
android:background="#FFC2A3">
<Button android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_save"
android:onClick="saveOnWeb"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#995A5A">
</View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:background="#F1C6B8">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/name"/>
<EditText android:id="@+id/name"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/email"/>
<EditText android:id="@+id/e-mail"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/login"/>
<EditText android:id="@+id/login-name"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/pass"/>
<EditText android:id="@+id/pass-word"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
【问题讨论】:
标签: android web-services post android-studio get