gpt4 book ai didi

android - 微调器显示错误的值

转载 作者:行者123 更新时间:2023-11-29 15:33:00 25 4
gpt4 key购买 nike

我有一个简单的程序,我将微调器设置到一个位置。然后我调用第二个模块,当我返回时,我重置微调器。微调器显示不显示微调器值。当您点击微调器时,它指向正确的值,但它显示的值不正确。事实上,它实际上是在下降。

我写了下面这个简单的程序来演示。仅当表单在 Linearlayout 或 TableLayout 中具有至少 1 个其他元素的微调器时才会发生这种情况。

主.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent" android:layout_height="200dp"
android:text="Main Form" />

<LinearLayout android:id="@+id/widget43"
android:layout_width="320dp" android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btn" android:text="Button" android:textSize="16sp"
android:layout_width="160dp" android:layout_height="40dp" />
<Spinner
android:id="@+id/btnFour" android:textSize="16sp"
android:layout_width="160dp" android:layout_height="40dp" />
</LinearLayout>
</LinearLayout>

下一个.xml

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

<TextView android:id="@+id/id1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
/>
</LinearLayout>

主.java

package tt.zzz;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

public class main extends Activity {

@Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
fillSpinner();

Button btnGo = (Button) findViewById(R.id.btn);
btnGo.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) { Go(); } });
}

void Go() {
Intent i = new Intent(this, next.class );
startActivityForResult( i, 0 );
}

public void fillSpinner(){
Spinner spin_test = (Spinner) findViewById( R.id.btnFour );

ArrayAdapter<CharSequence> myAdapter =
new ArrayAdapter<CharSequence>(
this,
android.R.layout.simple_spinner_item
);
myAdapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);

myAdapter.add("Option 1" );
myAdapter.add("Option 2" );
myAdapter.add("Option 3" );

spin_test.setAdapter(myAdapter);
spin_test.setSelection(1);

spin_test.setOnItemSelectedListener(
new Spinner.OnItemSelectedListener(){
public void onItemSelected(AdapterView<?>
arg0,View arg1,int arg2,long arg3){
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillSpinner();
}
}

下一个.java

package tt.zzz;

import android.app.Activity;
import android.os.Bundle;

public class next extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.next);
}
}

最佳答案

在您的 setSelection 之后,添加以下行:

myAdapter.notifyDataSetChanged();

关于android - 微调器显示错误的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3900445/

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