我有一个带有项目的微调器,通过ArrayAdapter填充.我想为spinner的组合框和列表框中的某些(不是所有)微调器项更改字体样式.我想我需要继承一些东西,但我不明白是什么.我怎样才能做到这一点?
谢谢!
我想做这样的事情,请帮帮我
Spinner spinner = (Spinner) findViewById(R.id.spinner5
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this,**R.array.country_array**, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter5);
Run Code Online (Sandbox Code Playgroud)
我需要使 R.array.country_array 成为动态的,例如将 country_code 更改为另一个数组名称,如 city_array 或 stat_array。
我试着写“R.array.”+dynamic_variable_array_name
但我失败了..任何帮助
我开发了一个Adroid应用程序。所以我想以编程方式自定义DropDown Spinner的行为。我覆盖了getDropDownView方法,但找不到任何东西可以更改DropDown的尺寸及其对齐方式。我只这样改变DropDown中每行的颜色
View view = this.getView(position, convertView, parent);
if (position % 2 == 0) {
view.setBackgroundColor(Color.YELLOW);
} else {
view.setBackgroundColor(Color.GRAY);
}
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?谢谢
我在一个活动中有三个微调器,我可以编辑用户已输入数据库的信息.我已经能够通过查询我的SQLite数据库来设置文本字段的文本,以匹配用户可以编辑的内容.用旋转器可以做同样的事吗?
例如,如果用户之前选择了2000年,则在新的编辑活动中我希望在2000处选择微调器,然后他们可以根据需要更改它.
到目前为止,我只看到了基于整数位置设置微调器位置的选项.这可以通过提供一年来完成吗?谢谢你的帮助.
这是我目前使用月份微调器处理的内容:
ArrayList<String> list = new ArrayList( Arrays.asList(getResources().getStringArray(R.array.months)) );
int pos = list.get("March");
spinMonth.setSelection(pos);
Run Code Online (Sandbox Code Playgroud) 我的项目运行良好,直到我为我的微调器声明了一个onItemSelctedListener ..现在我的项目没有运行..并且日志猫显示以下错误...
03-03 01:59:08.465: E/AndroidRuntime(1401):
FATAL EXCEPTION: main
Process: com.example.testqstn, PID: 1401
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.testqstn/com.example.testqstn.MainActivity}:
java.lang.IllegalStateException: System services not available to Activities
before onCreate()
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
at android.app.Activity.getSystemService(Activity.java:4532)
at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:153)
at com.example.testqstn.MainActivity.<init>(MainActivity.java:39)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at …Run Code Online (Sandbox Code Playgroud) 我一直在尝试学习在 Android Studio 中使用微调器小部件,但无论我使用什么教程,我总是在尝试使用 setAdapter() 函数时遇到相同的 NullPointerException 并在启动时崩溃。我尝试将内容视图切换到 setContentView(R.layout.content_main) 以查看是否可以在阅读此处的一些解决方案后解决它,但它没有用。
主要活动
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String[] country = {"Canada", "Mexico", "USA"};
ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, country);
Spinner spinner = (Spinner)findViewById(R.id.spinner);
spinner.setAdapter(stringArrayAdapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; …Run Code Online (Sandbox Code Playgroud) 我说的是页面加载过程中在选项卡上显示的图标。
铬:
Firefox(带有TreeTab插件):
你明白了。我想让它看起来像页面正在加载,已经加载了。某些事件触发的是javascript,然后该标签看起来像正在加载。有没有办法做到这一点?
我可以想到的一种方法是用微调器替换favicon,但我不确定是否可以即时更改,即使可以更改,也要跨浏览器操作很麻烦。
我正在使用角度 4 中材料角度的进度旋转器。在我的情况下,我需要旋转器边缘像所附图像中的那样是圆形的。不知道如何做到这一点,因为我使用 svg 的经验有点少。我创建了这个微调器,https://i.stack.imgur.com/aiEqI.png ,而我需要这个 https://i.stack.imgur.com/jV0Rs.png
我正在使用数据绑定应用自定义微调器。我以前从资源字符串数组传递数组,现在我从服务器获取数据,我需要将该数组放入微调器,那么我如何动态地做到这一点?就像这里我使用 android:entries 属性问题:如果从 API 获取数据,如何更新我的微调器值?
<data>
<variable
name="model"
type="com.abc.online.viewmodels.StoreHomeViewModel" />
</data>
<Spinner
android:id="@+id/isspSelectCity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@array/country_code_list"
android:gravity="center"
android:onItemSelected="@{(parent,view,pos,id)->model.onCitySelectItem(parent,view,pos,id)}" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我正在更换
android:entries="@array/country_code_list"
Run Code Online (Sandbox Code Playgroud)
和
android:entries="@{model.fetchCountriesCode()}"
Run Code Online (Sandbox Code Playgroud)
这是获取城市的功能
public List<String> fetchCountriesCode(){
List<String> list=new ArrayList<>();
if (getCitiesObj().getValue()!=null) {
Result[] cities = getCitiesObj().getValue().get(0).getResult();
for (Result cit : cities) {
list.add(cit.getName());
}
} return list;}
Run Code Online (Sandbox Code Playgroud)
android:entries 如果我们在渲染之前已经列出了值,则它不会在渲染后采用/更新值。那么我该怎么做呢?
我会来天堂还是下地狱?由于我必须填充5个微调器,我尝试了非常紧凑的代码.我不明白为什么我应该使用ArrayAdapter,所以我简单地将它删除了,尽管所有教程都使用它.因为它有效,我被贬低了.代码只显示一个微调器:
Spinner s2_height = (Spinner)findViewById(R.id.s2_height);
s2_height.setOnItemSelectedListener(new OnItemSelectedListener() { //Register a callback to be invoked when an item in this AdapterView has been selected.
public void onItemSelected(AdapterView<?> arg0, View arg1, //Callback method to be invoked when an item in this view has been selected
int arg2, long arg3) {
myCalc();}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的.java中的位置,在那里我删除了ArrayAdapter部分,通常在教程中重新编写为:
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.Height_array_id, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2_height.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,它有效,我放置了一个方法myCalc,它正确显示所有5个微调器上的ItemPosition.现在我担心我会在另一个地方出现任何缺点,可能会改变颜色或文字高度.有人有同样的问题吗?
我有这个数据 jsonParam.toString();
JSONObject jsonParam = new JSONObject();
Run Code Online (Sandbox Code Playgroud)
数据是: {"12":"SUBARU","13":"AUDI","14":"BMWA","15":"FORD","16":"HONDA"}
我想填充下拉列表(Android 中的 Spinner)并希望通过 Android 中的下拉列表从此数据中获取选定的值项 ID ..