gpt4 book ai didi

android - 带有 fragment 和 MySQL 数据库的微调器

转载 作者:行者123 更新时间:2023-11-28 23:19:09 25 4
gpt4 key购买 nike

这是输出图像:

Image

目前我正在处理一个注册表项目。因为我使用了四个 Spinner 和三个编辑文本,但是当我运行项目时,应用程序的顺序不正确,并且当屏幕尺寸不同时,表单也会发生变化。我希望应用程序按正确顺序排列并支持所有屏幕尺寸。我使用了 Fragment 但这也不起作用。

public class MainActivity extends ActionBarActivity {
ArrayList<String> listItems = new ArrayList<>();
ArrayList<String> listItems1 = new ArrayList<>();
ArrayList<String> listItems2 = new ArrayList<>();
ArrayList<String> listItems3 = new ArrayList<>();
ArrayAdapter<String> adapter;
Spinner sp, sp1, sp2, sp3;
EditText ed1, ed2, ed3;
Button b1;
String crop,state,cat,soil,GetpH, Getphos, Getpottas;
String DataParseUrl = "http://localhost/insert_agri.php";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ed1 = (EditText) findViewById(R.id.editText);
sp = (Spinner) findViewById(R.id.spinner);
BackTask bt = new BackTask();
bt.execute();

sp1 = (Spinner) findViewById(R.id.spinner2);

BackTask1 bt1 = new BackTask1();
bt1.execute();

sp2 = (Spinner) findViewById(R.id.spinner3);

BackTask2 bt2 = new BackTask2();
bt2.execute();

sp3 = (Spinner) findViewById(R.id.spinner4);

BackTask4 bt4 = new BackTask4();
bt4.execute();


ed1 = (EditText) findViewById(R.id.editText);
ed2 = (EditText) findViewById(R.id.editText2);
ed3 = (EditText) findViewById(R.id.editText3);

b1=(Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GetDataFromEditText();
sendDatatoServer(crop,state,cat,soil,GetpH, Getphos, Getpottas);
}
});
}



private void GetDataFromEditText() {
crop=sp.getSelectedItem().toString();
state=sp1.getSelectedItem().toString();
cat=sp2.getSelectedItem().toString();
soil=sp3.getSelectedItem().toString();
GetpH=ed1.getText().toString();
Getphos=ed2.getText().toString();
Getpottas=ed3.getText().toString();
}


private class BackTask extends AsyncTask<Void, Void, Void> {
ArrayList<String> list;

protected void onPreExecute() {
super.onPreExecute();
list = new ArrayList<>();
}

protected Void doInBackground(Void... params) {
InputStream is = null;
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://........php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
// Get our response as a String.
is = entity.getContent();
} catch (IOException e) {
e.printStackTrace();
}

//convert response to string
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"));
String line = null;
while ((line = reader.readLine()) != null) {
result += line;
}
is.close();
//result=sb.toString();
} catch (Exception e) {
e.printStackTrace();
}

try {

JSONObject jsono = new JSONObject(result);
JSONArray jArray = jsono.getJSONArray("agriculture");
for (int i = 0; i < jArray.length(); i++) {
JSONObject jsonObject = jArray.getJSONObject(i);

list.add(jsonObject.getString("crop"));
// list.add(jsonObject.getString("country"));

}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}

protected void onPostExecute(Void result) {
listItems.addAll(list);
adapter = new ArrayAdapter<String>(MainActivity.this, R.layout.spinner_layout, R.id.txt, listItems);
sp.setAdapter(adapter);
}
}

我的 XML 文件也附加了这个。

Activity 主体

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.tony.agri.MainActivity"
android:orientation="vertical"
android:weightSum="1">


<TextView
android:text="Enter Details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="136dp"
android:layout_marginStart="136dp"
android:layout_marginTop="14dp"
android:id="@+id/textView15" />

<TextView
android:text="crop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView15"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="41dp"
android:id="@+id/textView16" />

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView16"
android:layout_centerHorizontal="true"
android:id="@+id/spinner" />

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView17"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:id="@+id/spinner2" />

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/spinner3" />

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView19"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:id="@+id/spinner4" />

<TextView
android:text="pH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/spinner4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="12dp"
android:id="@+id/textView20" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_below="@+id/spinner4"
android:layout_alignLeft="@+id/textView15"
android:layout_alignStart="@+id/textView15"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp"
android:id="@+id/editText" />

<TextView
android:text="pospurs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="11dp"
android:id="@+id/textView21" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<TextView
android:text="pottasm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="13dp"
android:id="@+id/textView22" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_below="@+id/editText2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/editText3" />

<TextView
android:text="state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:id="@+id/textView17"
android:layout_below="@+id/spinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:text="category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView18"
android:layout_above="@+id/spinner3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:text="soil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:id="@+id/textView19"
android:layout_below="@+id/spinner3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/textView15"
android:layout_alignEnd="@+id/textView15"
android:id="@+id/button" />

旋转布局.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<TextView
android:id="@+id/txt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<TextView
android:id="@+id/txt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
/>

最佳答案

用您的 xml 替换下面的代码

它适用于您的设计问题。我无法理解您的订单问题。请给我更多详细信息。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.tony.agri.MainActivity"
android:orientation="vertical"
>


<TextView
android:text="Enter Details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView15" />

<TextView
android:text="crop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView16" />

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner" />

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner2" />

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner3" />

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner4" />

<TextView
android:text="pH"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/spinner4"
android:id="@+id/textView20" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/editText" />

<TextView
android:text="pospurs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView21" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/editText2" />

<TextView
android:text="pottasm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView22" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/editText3" />

<TextView
android:text="state"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView17" />

<TextView
android:text="category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView18" />

<TextView
android:text="soil"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView19" />

<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button" />

关于android - 带有 fragment 和 MySQL 数据库的微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42571867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com