जवाबों:
डिफ़ॉल्ट रूप EditTextसे एंड्रॉइड के सभी विजेट बहु-पंक्तिबद्ध हैं।
यहाँ कुछ नमूना कोड है:
<EditText
android:inputType="textMultiLine" <!-- Multiline input -->
android:lines="8" <!-- Total Lines prior display -->
android:minLines="6" <!-- Minimum lines -->
android:gravity="top|left" <!-- Cursor Position -->
android:maxLines="10" <!-- Maximum Lines -->
android:layout_height="wrap_content" <!-- Height determined by content -->
android:layout_width="match_parent" <!-- Fill entire width -->
android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>
inputTypeकम से कम linesऔर minLinesविशेषताओं को नकारते हुए । मेरे पास inputType="phone"और रेखाओं का कोई प्रभाव नहीं था
IndexOutOfBoundsExceptionजैसे ही आप की वजह से कुछ लिखते हीandroid:inputType="textMultiLine"
आपको इसका उपयोग करना बेहतर लग सकता है:
<EditText
...
android:inputType="textMultiLine"
/>
इसका कारण यह है कि android:singleLineपदावनत किया जाता है।
singleLineअपने उत्तर के लंबे समय ( हटाए गए समय) को हटा दिया था। सवाल के बारे में ही, यह उनके जवाब का सबसे महत्वपूर्ण हिस्सा है।
IndexOutOfBoundsExceptionआप कुछ लिखते हैं जैसे ही। मल्टीलाइन अब डिफ़ॉल्ट है।
यह मेरे लिए काम करता है, वास्तव में ये 2 विशेषताएं महत्वपूर्ण हैं: इनपुट टाइप और लाइनें । इसके अलावा, आपको एक स्क्रॉलबार की आवश्यकता हो सकती है, नीचे दिए गए कोड से पता चलता है कि एक कैसे बनाया जाए:
<EditText
android:id="@+id/addr_edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|left"
android:inputType="textEmailAddress|textMultiLine"
android:lines="20"
android:minLines="5"
android:scrollHorizontally="false"
android:scrollbars="vertical" />
इस तरह मैंने नीचे दिए गए कोड स्निपेट को लागू किया और यह ठीक काम कर रहा है। आशा है, यह किसी की मदद करेगा।
<EditText
android:id="@+id/EditText02"
android:gravity="top|left"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:lines="5"
android:scrollHorizontally="false"
/>
चीयर्स! ...धन्यवाद।
यह प्रयास करें, इन पंक्तियों को अपने संपादित पाठ दृश्य में जोड़ें, मैं मेरा जोड़ दूँगा। सुनिश्चित करें कि आप इसे समझते हैं
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText_newprom_description"
android:padding="10dp"
android:lines="5"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:minLines="5"
android:gravity="top|left"
android:scrollbars="vertical"
android:layout_marginBottom="20dp"/>
और अपने जावा क्लास पर क्लिक एडिटर को इस एडिट टेक्स्ट को निम्न प्रकार से बनाएं, मैं आपके अनुसार, मेरा नाम जोड़ दूंगा।
EditText description;
description = (EditText)findViewById(R.id.editText_newprom_description);
description.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
यह मेरे लिए ठीक काम करता है
EditText के पास एकल संपत्ति है। आप एक्सएमएल में या सेटसिंगलीन (झूठा) कॉल करके सेट कर सकते हैं; http://developer.android.com/reference/android/widget/TextView.html#setSingleLine%28%29
ये सभी अच्छे हैं, लेकिन ऊपरी स्तर के स्क्रॉल दृश्य के अंदर आपके एडिटेक्स होने की स्थिति में काम नहीं करेंगे :) शायद सबसे आम उदाहरण "सेटिंग" दृश्य है जिसमें इतने आइटम हैं कि वे दृश्य क्षेत्र से परे जाते हैं। इस स्थिति में आपने उन सभी को स्क्रॉल दृश्य में डाल दिया है, जिससे सेटिंग स्क्रॉल हो सके। ऐसी स्थिति में जब आपको अपनी सेटिंग में मल्टीलाइन स्क्रॉलेबल एडिट टेक्स्ट की आवश्यकता होती है, तो उसका स्क्रॉल काम नहीं करेगा।
<EditText
android:id="@id/editText" //id of editText
android:gravity="start" // Where to start Typing
android:inputType="textMultiLine" // multiline
android:imeOptions="actionDone" // Keyboard done button
android:minLines="5" // Min Line of editText
android:hint="@string/Enter Data" // Hint in editText
android:layout_width="match_parent" //width editText
android:layout_height="wrap_content" //height editText
/>
उन पंक्तियों की संख्या को अक्षम करने के लिए जिन्हें पहले थीम उपयोग xml विशेषता में सौंपा गया था: android:lines="@null"
मैंने इसे http://www.pcsalt.com/android/edittext-with-single-line-line-wrapping-and-done-action-in-android/ से सीखा है , हालाँकि मुझे खुद वेबसाइट पसंद नहीं है। यदि आप बहुस्तरीय BUT पोस्ट बटन के रूप में एंटर बटन को बनाए रखना चाहते हैं, तो लिस्टव्यू की "क्षैतिज स्क्रॉलिंग" को गलत पर सेट करें।
android:scrollHorizontally="false"
यदि यह xml में काम नहीं करता है, तो यह प्रोग्राम अजीब तरह से काम करता है।
listView.setHorizontallyScrolling(false);
<EditText
android:hint="Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textMultiLine|textNoSuggestions"
android:id="@+id/edittxtAddress"
android:layout_marginLeft="@dimen/textsize2"
android:textColor="@android:color/white"
android:scrollbars="vertical"
android:minLines="2"
android:textStyle="normal" />
और गतिविधि में "\ n" निकालने के लिए उपयोगकर्ता प्रेस नेक्लाइन है
String editStr= edittxtAddress.getText().toString().trim();
MyString= editStr.replaceAll("\n"," ");
अगर कुछ एक उपयोग कर रहा है AppCompatEditText तो आप स्थापित करने की आवश्यकता inputType = "textMultiLine" यहाँ कोड आप कॉपी कर सकते हैं
<androidx.appcompat.widget.AppCompatEditText
android:padding="@dimen/_8sdp"
android:id="@+id/etNote"
android:minLines="6"
android:singleLine="false"
android:lines="8"
android:scrollbars="vertical"
android:background="@drawable/rounded_border"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_25sdp"
android:layout_marginTop="32dp"
android:layout_marginEnd="@dimen/_25sdp"
android:autofillHints=""
android:gravity="start|top"
android:inputType="textMultiLine"
/>
पृष्ठभूमि के लिए
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/_5sdp"/>
<stroke android:width="1dp" android:color="#C8C8C8"/>
</shape>