gpt4 book ai didi

android - 在选定的微调项上显示编辑文本

转载 作者:行者123 更新时间:2023-11-29 15:21:24 26 4
gpt4 key购买 nike

我的类(class)有一个 Spinner,其中包含某些项目。我必须显示一个 EditText,我已将其可见性设置为“不可见”。当在微调器中选择“其他”项目时,我需要显示此 EditText

这是我的代码:-

Activity class:-




protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.maintenance);

ETServiceStation = (EditText)findViewById(R.id.ETServiceStation);
ETServiceType = (EditText)findViewById(R.id.ETServiceType);
ETServiceCost= (EditText)findViewById(R.id.ETServiceCost);

spinServiceType = (Spinner)findViewById(R.id.spinServiceType);
btnMaintenenceSave= (ImageButton)findViewById(R.id.btnMaintenenceSave);
btnMaintenanceClear = (ImageButton)findViewById(R.id.btnMaintenenceClear);

spinServiceType.setOnItemSelectedListener(this);

btnMaintenanceClear.setOnClickListener(this);
btnMaintenenceSave.setOnClickListener(this);

ArrayAdapter<String> serviceTypeAdapter = new ArrayAdapter<String>(getApplicationContext(), R.array.service_type_array, android.R.layout.simple_spinner_item);
serviceTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinServiceType.setAdapter(serviceTypeAdapter);


}



public void onItemSelected(AdapterView<?> parent, View view, int servicePos, long id)
{
// TODO Auto-generated method stub
spinnerServiceType = spinServiceType.getItemAtPosition(servicePos).toString();


if(spinnerServiceType.matches("Others"))
{
ETServiceType = (EditText)findViewById(R.id.ETServiceType);
ETServiceType.setVisibility(View.VISIBLE);
spinnerServiceType = ETServiceType.getText().toString();
}
serviceType = spinnerServiceType;
}
}



Resource:-

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="service_type_array">
<item>Full Service</item>
<item value="serviceother">Other</item>

</string-array>
</resources>




maintenance.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="30dp">

<TextView
android:id="@+id/txtMTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Maintenance"
android:layout_gravity="center_horizontal"
android:textSize="25sp"
android:textColor="@color/SteelBlue"
android:typeface="sans"/>


<TextView
android:layout_marginTop="60dp"
android:id="@+id/txtServiceStation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Service station name:" />

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

<requestFocus />
</EditText>

<TextView
android:id="@+id/txtServiceType"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Service type: "/>

<Spinner
android:id="@+id/spinServiceType"
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

<EditText
android:id="@+id/ETServiceType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:visibility="invisible"
android:ems="10" />

<TextView
android:id="@+id/txtServiceCost"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Servicing expence:" />

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginLeft="50dp"
android:orientation="horizontal">
<ImageButton
android:id="@+id/btnMaintenenceSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:src="@drawable/fuelbtnsaveclick" />

<ImageButton
android:id="@+id/btnMaintenenceClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:background="@color/white"
android:src="@drawable/fuelbtnclearclick" />

</LinearLayout>
</LinearLayout>


Database:
public long createMainEntry(MaintenanceExpense me)
{
ContentValues mcv = new ContentValues();
mcv.put(KEY_SERVICE_STATION,me.getServiceStation());
mcv.put(KEY_SERVICE_TYPE,me.getServiceType());
mcv.put(KEY_SERVICE_COST,me.getServiceCost());
return otherInfoDatabase.insert(MAINTENANCE_DATABASE_TABLE, null, mcv);
}

单击“其他”项时,我必须显示 ETServiceType。感谢您的帮助。

最佳答案

public void onItemSelected(AdapterView<?> parent, View view, int position, long id) 
{
if(spinServiceType.getItemAtPosition(position).toString().equalsIgnorecase("Others")
{
editextObject.setVisibility(View.VISIBLE);
}
}

关于android - 在选定的微调项上显示编辑文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17858051/

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