我只是下载车轮选择器示例项目。在该项目中,它在车轮选择器中选择了它在文本视图中更新。在这里我将该文本视图更改为按钮,如果我单击该按钮意味着它将显示轮选择器中的值。它可能与否?
这里是我的示例代码:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_wheel_layout);
bundle = new Bundle();
wheelArrayList = new ArrayList<String>();
bundle = getIntent().getExtras();
wheelArrayList = (ArrayList<String>) bundle.get("ItemKey");
wheelMenu1 = wheelArrayList.toArray(new String[wheelArrayList.size()]);
initWheel1(R.id.p1);
btnCurrentSelection = (Button) this.findViewById(R.id.btn_FrstSelection);
btnCurrentSelection.setText(bundle.getString("selectedValue"));
btnCurrentSelection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//OnWheelChangedListener();
}
});
}
// Wheel scrolled listener
OnWheelScrollListener scrolledListener = new OnWheelScrollListener()
{
public void onScrollStarts(WheelView wheel)
{
wheelScrolled = true;
}
public void onScrollEnds(WheelView wheel)
{
wheelScrolled = false;
updateStatus();
}
};
// Wheel changed listener
private final OnWheelChangedListener changedListener = new OnWheelChangedListener()
{
public void onChanged(WheelView wheel, int oldValue, int newValue)
{
if (!wheelScrolled)
{
updateStatus();
}
}
};
/**
* Updates entered PIN status
*/
private void updateStatus()
{
PreferenceConnector.writeString(WheelActivity.this, itemKeyName, wheelMenu1[getWheel(R.id.p1).getCurrentItem()]);
}
}
/**
* Initializes wheel
*
* @param id
* the wheel widget Id
*/
private void initWheel1(int id)
{
WheelView wheel = (WheelView) findViewById(id);
wheel.setAdapter(new ArrayWheelAdapter<String>(wheelMenu1));
wheel.setVisibleItems(5);
wheel.setCurrentItem(0);
// text.setText(""+wheel.getCurrentItem());
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
}
/**
* Returns wheel by Id
*
* @param id
* the wheel Id
* @return the wheel with passed Id
*/
private WheelView getWheel(int id)
{
return (WheelView) findViewById(id);
}
/**
* Tests wheel value
*
* @param id
* the wheel Id
* @param value
* the value to test
* @return true if wheel value is equal to passed value
*/
private int getWheelValue(int id)
{
return getWheel(id).getCurrentItem();
}
任何人帮助我,如何集中注意力
答案 0 :(得分:1)
现在我得到了解决方案。这里是代码
btnCurrentSelection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int id = getIndex(wheelMenu1, btnCurrentSelection.getText()
.toString());
getWheel(R.id.p1).setCurrentItem(id);
}
});
public int getIndex(String[] array, String specificValue) {
for (int i = 0; i < array.length; i++) {
if (array[i].equals(specificValue)) {
return i;
}
}
return 0;
}