How to add multiple fetching data in single spinner using array adapter - android-studio

My code:
Added data in array adapter but last data only comming how to add all the data in spinner using arrayadapter
while (rs.next()) {
int_EMP_ID = rs.getInt("EmpID");
str_EMP_Name = rs.getString("EmployeeName");
int User_ID_List[] = {int_EMP_ID};
String User_name_List[] = {str_EMP_Name};
for (int i=0;i<=10;i++) {
// Step 2: Create and fill an ArrayAdapter with a bunch of "State" objects
ArrayAdapter<Employee> spinnerArrayAdapter = new ArrayAdapter<Employee>(this, android.R.layout.simple_spinner_item, new Employee[]{
new Employee(User_ID_List[i], User_name_List[i]),
new Employee(User_ID_List[i], User_name_List[i])
});
}
Blockquote

<string-array name="array_name">
<item>Array Item One</item>
<item>Array Item Two</item>
<item>Array Item Three</item>
</string-array>
in your layout file.
<Spinner
android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:entries="#array/array_name"
/>

Finally got answer
List<Employee> DVDList = new ArrayList<Employee>();
while (rs.next()) {
int_EMP_ID = rs.getInt("EmpID");
str_EMP_Name = rs.getString("EmployeeName");
int i = rs.getInt("EmpID");
String s = rs.getString("EmployeeName");
Employee context = new Employee(int_EMP_ID, str_EMP_Name);
context.setEMPId(i);
context.setEmpName(s);
DVDList.add(context);
}
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, DVDList);
spinner.setAdapter(adapter);
}

Related

I need a particular layout of elements in my Android Studio

I have asked similar question elsewhere but I'm posting a new question.
I wanted layout like this
txt[1] tv[1]
txt[2]tv[2]
...
txt[8] tv[8]
My Attepmt, the main lane is this:
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
but it doesn't work.
My code
public void click2(View view) {
Button button3 = findViewById(R.id.button2);
button3.setText("hello");
// Put buttons into an array
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.activity_main);
// GridLayout gridLayout=(GridLayout) findViewById(R.id.activity_main);
// Put buttons into an array
// Button[] txt = {new Button(this), new Button(this)};
Button[] txt = new Button[8];
TextView[] tv = new TextView[8];
// loop over all values of i between 0 to the end of the button array
for (int i = 0; i < txt.length; i = i + 1) {
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
// Access array elements by index so txt1 is txt[1], etc.
txt[i]=new Button(this);
txt[i].setText(Integer.toBinaryString(i));
linearLayout.addView(txt[i]);
tv[i]=new TextView(this);
linearLayout.addView(tv[i]);
}
};

MPAndroidChart not working. Failed to add data into PieEntry

Failed to add data into PieEntry. All the dependencies and repositories are added correctly. It can run, but the output is not as same as what I code in. I have no idea about how to solve it.
Main Activity:
private void ShowPieChart() {
ArrayList<PieEntry> pieEntries = new ArrayList<>();
String label = "type";
//initializing data
Map<String, Integer> typeAmountMap = new HashMap<>();
typeAmountMap.put("Toys",200);
typeAmountMap.put("Snacks",230);
typeAmountMap.put("Clothes",100);
typeAmountMap.put("Stationary",500);
typeAmountMap.put("Phone",50);
//initializing colors for the entries
ArrayList<Integer> colors = new ArrayList<>();
colors.add(Color.parseColor("#304567"));
colors.add(Color.parseColor("#309967"));
colors.add(Color.parseColor("#476567"));
colors.add(Color.parseColor("#890567"));
colors.add(Color.parseColor("#a35567"));
colors.add(Color.parseColor("#ff5f67"));
colors.add(Color.parseColor("#3ca567"));
//input data and fit data into pie chart entry
for(String type: typeAmountMap.keySet()){
pieEntries.add(new PieEntry(typeAmountMap.get(type).floatValue(), type));
}
PieDataSet pieDataSet = new PieDataSet(pieEntries,label);
pieDataSet.setValueTextSize(12f);
pieDataSet.setColors(colors);
PieData pieData = new PieData(pieDataSet);
pieData.setDrawValues(true);
pieChart.setData(pieData);
pieChart.invalidate();
pieChart.setUsePercentValues(true);
pieChart.getDescription().setEnabled(false);
pieChart.setRotationEnabled(true);
pieChart.setDragDecelerationFrictionCoef(0.9f);
pieChart.setRotationAngle(0);
pieChart.setHighlightPerTapEnabled(true);
pieChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
pieChart.setHoleColor(Color.parseColor("#000000"));
}
XML:
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/pieChart"
android:layout_above="#+id/bottom_navi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="160dp"
android:layout_marginLeft="160dp"
android:layout_marginTop="287dp"
android:layout_marginEnd="144dp"
android:layout_marginRight="144dp"
android:layout_marginBottom="391dp" />

How can I collapse and expand the recycler view layout when the button is clicked?

I am developing a recycler view with Kotlin. Let's look at my code, when I click on the orderProduct button, the orderRecyclerview is visible and on the contrary, when I click again, the visible is gone. But sometimes when I click on it, the recycler view is shown and sometimes it is not shown.
So how can I do this anytime? How can I solve this bug?
orderProduct.setOnClickListener{
orderProduct.setCompoundDrawablesWithIntrinsicBounds(0, 0, if (!isClicked) R.drawable.btn_down else R.drawable.btn_up, 0)
if (isClicked) {
var r = Runnable {
try {
orderRecyclerview.visibility=View.VISIBLE
paymentList= paymentDb?.paymentDao()?.getAll()!!
mAdapter = PaymentRecylcerViewAdapter(this, paymentList)
mAdapter.notifyDataSetChanged()
orderRecyclerview.adapter = mAdapter
orderRecyclerview.layoutManager = LinearLayoutManager(this)
orderRecyclerview.setHasFixedSize(false)
}catch (e: Exception) {
}
}
val thread = Thread(r)
thread.start()
}else {
orderRecyclerview.visibility=View.GONE
}
isClicked = !isClicked
}
Firstly, you can move this code above the onclickListner.
paymentList= paymentDb?.paymentDao()?.getAll()!!
mAdapter = PaymentRecylcerViewAdapter(this, paymentList)
mAdapter.notifyDataSetChanged()
orderRecyclerview.adapter = mAdapter
orderRecyclerview.layoutManager = LinearLayoutManager(this)
orderRecyclerview.setHasFixedSize(false)
Then inside the onClickListner handle visibility of orderRecyclerview.
For better user experience, You can also add animation in this.
Hope, it will help.
add Dependecy
compile 'net.cachapa.expandablelayout:expandablelayout:2.9.2'
<net.cachapa.expandablelayout.ExpandableLayout
android:id="#+id/expandable_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:el_duration="1000"
app:el_expanded="true"
app:el_parallax="0.5">
<RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="Fixed height" />
To trigger the animation, simply grab a reference to the ExpandableLayout from your Java code and and call either of expand(), collapse() or toggle().

Add a lookup field for a list in Sharepoint Client Model

This is what I've achieved do far:
Field parent = list.Fields.AddFieldAsXml(
#"<Field Type='Lookup' DisplayName='ParentContentType'
Required='FALSE' EnforceUniqueValues='FALSE'
List= 'ContentTypes'
ShowField='Title' UnlimitedLengthInDocumentLibrary='FALSE'
RelationshipDeleteBehavior='None'
StaticName='ParentContentType' Name='ParentContentType'/>",
true, AddFieldOptions.DefaultValue);
But I am not able to set the Get information from: value for this lookup field.
Can anyone please suggest how to achieve it?
Code added:
var listCreationInfo = new ListCreationInformation();
listCreationInfo.Title = "New List";
listCreationInfo.TemplateType = (int)ListTemplateType.CustomGrid;
List list = web.Lists.Add(listCreationInfo);
list.Update();
ctxt.ExecuteQuery();
Field parent = list.Fields.AddFieldAsXml(
#"<Field Type='Lookup' DisplayName='ParentContentType'
Required='FALSE' EnforceUniqueValues='FALSE'
List= 'ContentTypes'
ShowField='Title' UnlimitedLengthInDocumentLibrary='FALSE'
RelationshipDeleteBehavior='None'
StaticName='ParentContentType' Name='ParentContentType'/>",
true, AddFieldOptions.DefaultValue);
Please try this.
public static void AddLookupField()
{
string lookupSchema = #"<Field Type='Lookup' DisplayName='mylookup2'
Required='FALSE' EnforceUniqueValues='FALSE'
List='{70d6098c-6ba0-4e9e-b101-a60b88fc226a}'
ShowField='Title' UnlimitedLengthInDocumentLibrary='FALSE'
RelationshipDeleteBehavior='None'
StaticName='mylookup' Name='mylookup2'/>";
ClientContext clientContext = new ClientContext("http://sharepoint10");
List list = clientContext.Web.Lists.GetByTitle("listtitle");
FieldCollection fields = list.Fields;
clientContext.Load(list);
clientContext.Load(fields);
clientContext.ExecuteQuery();
Field lookupField = fields.AddFieldAsXml(lookupSchema, true, AddFieldOptions.AddToDefaultContentType);
lookupField.Update();
clientContext.Load(lookupField);
clientContext.ExecuteQuery();
}

How to bind String[] values in listview using hashmap in android?

Hi I am trying to get values using hashmap<> using .net web services in android. I have custemized adapter, I am trying to do this.
SoapObject folderResponse = (SoapObject)envelope.getResponse();
Log.i("AllFolders", folderResponse.toString());
String[] folderslist = new String[folderResponse.getPropertyCount()];
//getting values using folderslist.
ArrayList<HashMap<String, String>> hashfoldersList = new ArrayList <HashMap<String, String> >();
//But I want hashfoldersList list in my custamized adapter.
for(i=0; i<folderResponse.getPropertyCount(); i++) {
SoapObject SingleFolder = (SoapObject)folderResponse.getProperty(i);
Log.i("SingleFolder", SingleFolder.toString());
ID= SingleFolder.getProperty(0).toString();
KEY_Name = SingleFolder.getProperty(1).toString();
ParentID = SingleFolder.getProperty(2).toString();
CreatedBy= SingleFolder.getProperty(3).toString();
System.out.println(ID);
System.out.println(KEY_Name);
System.out.println(ParentID);
System.out.println(CreatedBy);
SoapPrimitive Record =(SoapPrimitive) SingleFolder.getProperty(1);
Log.i("Record", Record.toString());
{
folderslist[i] = SingleFolder.getProperty(0).toString();
}
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
org.w3c.dom.Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = (NodeList) doc.getElementsByTagName(ID);
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(ID, parser.getValue(e, ID));
map.put(KEY_Name, parser.getValue(e, KEY_Name));
map.put(ParentID, parser.getValue(e, ParentID));
map.put(CreatedBy, parser.getValue(e, CreatedBy));
foldersList.add(map);
}
listview = (ListView)findViewById(R.id.listview);
adapter=new LazyAdapter(this, hashfoldersList);
//My custemized adapter.
listview.setAdapter(adapter);
listview.setOnItemClickListener(this);
}
}
Please suggest, how to get values in list using ArrayList> hashfolderlist, as I am using string[] folderlist. when I am inserting hashfolderlist, it is giving error. Please suggest. thanks
mate you should have a simple adapter to take the strings and put it inside a listview.
second you should have 2 textviews
SimpleAdapter adapter = new SimpleAdapter(this, list,
R.layout.your_activity, new String[] { "", "" },
new int[] { R.id.textview1, R.id.textView2 }
);
listView1.setAdapter(adapter);
hope it helps you!!

Resources