在应用程序的java部分创建EditText时,如何将其限制为与xml中的数字相同?例如:
new EditText(this);
Run Code Online (Sandbox Code Playgroud)
设置像
<EditText
android:id="@+id/h1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"/>
Run Code Online (Sandbox Code Playgroud) 我正在构建一个基于外部数据获取布局的应用程序.根据indata,布局分为不同的块.这些块在viewflipper的帮助下显示.在每个块中,暂时存在一个或多个"textview"和"edittext".在鳍状肢的第一页上,所有数据都在textviews和edittexts中显示.但是在viewflipper的其他页面上,edititexts中的值才会显示,直到edittext聚焦为止.我不知道为什么.所以要清楚.所有edittexts的值实际上都存在,但在edittext聚焦之前不会显示.在我运行应用程序的所有设备上(模拟器,HTC Desire,HTC Wildfire),问题都是一样的.有谁知道如何解决这个问题?
这是生成布局的类:
public class ModuleLayout extends LinearLayout {
public ModuleLayout(Context context, ArrayList<BaseModuleItem> itemList) {
super(context);
TableLayout tempTable = new TableLayout(context);
for (int i = 0; i < itemList.size(); i++)
{
TableRow tempRow = new TableRow(context);
TextView tempTextView = new TextView(context);
tempTextView.setText(itemList.get(i).getName());
EditText tempEditText = new EditText(context);
tempEditText.setText(itemList.get(i).getItemValue());
tempRow.addView(tempTextView);
tempRow.addView(tempEditText);
tempTable.addView(tempRow);
}
tempTable.setColumnStretchable(1, true);
this.addView(tempTable);
}
}
Run Code Online (Sandbox Code Playgroud)
这是行动中问题的图片.

左图显示其所有值都很好.右侧图片位于viewflipper中的第二个位置,并且不显示edittexts中的值,第一个具有焦点的例外情况除外.我还应该提一下,在edittext获得焦点之后,即使我在viewflipper中的其他视图然后返回,它仍继续显示该值.
当我使用"EditText"时,我有虚拟键盘.
按第一次"后退"按钮可隐藏键盘.第二次按下在我的活动中调用"onBackPressed"回调.好的但是...
我不知道如何勾选第一台印刷机.我需要在虚拟键盘解除后立即处理输入数据.
欢迎任何想法.
谢谢.
我一直在关注官方Android教程,并且在按下"Enter"为EditText后执行函数这个非常简单的示例时遇到了问题.
我明白我应该做什么,并且似乎已经正确设置了所有东西,但Eclipse正在抱怨这条线:
edittext.setOnKeyListener(new OnKeyListener() {
Run Code Online (Sandbox Code Playgroud)
它强调setOnKeyListener错误:
类型View中的方法setOnKeyListener(View.OnKeyListener)不适用于参数(new DialogInterface.OnKeyListener(){})
并且还强调OnKeyListener了错误:
新类型DialogInterface.OnKeyListener(){}必须实现继承的抽象方法DialogInterface.OnKeyListener.onKey(DialogInterface,int,KeyEvent)
也许有人可以朝着正确的方向射击我?在我尝试其他解决方案之前(我已经在stackoverflow上找到),我真的很想解决这个问题,因为它让我感到慌乱,因为官方教程看起来不那么简单.
提前致谢.
我只是想在用户按下editText时输入事件.
我没有得到Toast的消息,没有得到"Enter press"而不是"按下了一些键!" 无论是.
什么mi做错了?
myEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Toast.makeText(getApplicationContext(), "Some key pressed!", Toast.LENGTH_LONG).show();
if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
Toast.makeText(getApplicationContext(), "Enter pressed", Toast.LENGTH_LONG).show();
return true;
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
编辑:
好吧,它正在Android 2.3.3上工作,而不是在4.1.2 任何想法我怎么能在任何Android设备上使这个工作?
我想在警告对话框中添加两个编辑文本字段.就像解决方案听起来那么简单,我还没有能够收集一个工作的.我无法同时设置两个(编辑文本)视图.
如果您想查看更多代码,请发表评论.
alertDialog.setTitle("Values");
final EditText quantity = new EditText(SecondScan.this);
final EditText lot = new EditText(SecondScan.this);
quantity.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
lot.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
Project=arr[0].toString();
Item=arr[1].toString();
alertDialog.setMessage( "Employee No. : " + (Login.user).trim()+
"\nWarehouse : " + (FirstScan.Warehouse).trim()+
"\nLocation : " + (FirstScan.Location).trim()+
"\nProject : " + Project.trim() +
"\nItem : " + Item.trim() +
"\nLot : " + Lot.trim()+
"\n\nQuantity :" );
alertDialog.setView(quantity);
alertDialog.setView(lot);
// the bit of code that doesn't seem to be working.
alertDialog.setCancelable(false);
alertDialog.setPositiveButton("Update", new DialogInterface.OnClickListener() {
public void …Run Code Online (Sandbox Code Playgroud) 我正在制作一个计算器,我想确保用户能够输入"负十进制数"我单独看到xml文件中的选项,例如为了输入十进制数,EditText的inputType必须是numberDecimal,并且负数,inputType必须是"numberSigned",但我需要两者.如果我选择inputType作为"text",那么如果不是数字,用户可以输入抛出异常的任何内容.我不知道如何解决这个问题.
我已经在Gmail收据字段中搜索了一种具有类似外观的方法,该字段允许以非常酷的方式自动填充项目:

构建在Android框架中并负责此类的类称为" MultiAutoCompleteTextView ".
MultiAutoCompleteTextView是非常基础的,但它没有足够的样本,教程和库来了解如何在Gmail和类似的东西上自定义它.
我想知道如何自定义它来处理任何类型的数据,并且我将完全控制它(例如添加,删除和获取它已自动完成的项目).
我找到了下一步实现它的方法:
我决定使用#3(谷歌的芯片库).
目前获取Google图书馆使用的联系人列表的代码:
public List<RecipientEntry> doQuery() {
final Cursor cursor = mContentResolver.query(mQuery.getContentUri(), mQuery.getProjection(), null, null, null);
final LinkedHashMap<Long, List<RecipientEntry>> entryMap = new LinkedHashMap<Long, List<RecipientEntry>>();
final List<RecipientEntry> nonAggregatedEntries = new ArrayList<RecipientEntry>();
final Set<String> existingDestinations = new HashSet<String>();
while (cursor.moveToNext())
putOneEntry(new TemporaryEntry(cursor, false /* isGalContact */), true, entryMap, nonAggregatedEntries,
existingDestinations);
cursor.close();
final List<RecipientEntry> entries = new ArrayList<RecipientEntry>();
{
for (final …Run Code Online (Sandbox Code Playgroud) android autocomplete android-edittext multiautocompletetextview
如何在EditText的中心设置提示文本并将光标设置在EditText的左侧部分?当我开始输入文本时,它从中心EditText开始?
我现在有
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/line_white"
android:layout_marginBottom="25dp"
android:paddingBottom="16dp"
android:gravity="center_horizontal">
<EditText
android:id="@+id/loginEmailField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoText="false"
android:ems="10"
android:hint="Choose an email adress"
android:inputType="textEmailAddress"
android:paddingLeft="2dp"
android:singleLine="false"
android:textColor="#ffffff"
android:textColorHint="#9377ab"
android:textSize="19sp"
android:textStyle="bold"
android:background="#00000000"
android:layout_marginRight="2dp"
android:gravity="center"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) android ×10
android-edittext ×10
java ×2
autocomplete ×1
back ×1
enter ×1
exception ×1
keyboard ×1
math ×1
viewflipper ×1
views ×1