Android : how to get converted in to int with edittext which is in another layout, but in same activity

on Wednesday, January 28, 2015


here i have one code... which is using graph-view, but it is not getting worked, please help me. i used graph view and want to have dynamic value inserted in it. i used parsing int..


MainActivity.java:



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(this);
et1 = (EditText) findViewById(R.id.editText1);
et2 = (EditText) findViewById(R.id.editText2);
et3 = (EditText) findViewById(R.id.editText3);
et4 = (EditText) findViewById(R.id.editText4);
et5 = (EditText) findViewById(R.id.editText5);
et6 = (EditText) findViewById(R.id.editText6);

}


@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
super.setContentView(R.layout.graph);
LayoutInflater factory=getLayoutInflater();
View sulla=factory.inflate(R.layout.activity_main, null);
et1=(EditText) sulla.findViewById(R.id.editText1);
et2=(EditText) sulla.findViewById(R.id.editText2);
et3=(EditText) sulla.findViewById(R.id.editText3);
et4=(EditText) sulla.findViewById(R.id.editText4);
et5=(EditText) sulla.findViewById(R.id.editText5);
et6=(EditText) sulla.findViewById(R.id.editText6);
i1= Integer.parseInt(et1.getText().toString());
i2= Integer.parseInt(et2.getText().toString());
i3= Integer.parseInt(et3.getText().toString());
i4= Integer.parseInt(et4.getText().toString());
i5= Integer.parseInt(et5.getText().toString());
i6= Integer.parseInt(et6.getText().toString());

GraphView graph=(GraphView) findViewById(R.id.graph);

BarGraphSeries<DataPoint> series = new BarGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, i1),
new DataPoint(1, i2),
new DataPoint(2, i3),
new DataPoint(3, i4),
new DataPoint(4, i5),
new DataPoint(5, i6)
});
graph.addSeries(series);

// styling
series.setValueDependentColor(new ValueDependentColor<DataPoint>() {
@Override
public int get(DataPoint data) {
return Color.rgb((int) data.getX()*255/4, (int) Math.abs(data.getY()*255/6), 100);
}
});

series.setSpacing(50);

// draw values on top
series.setDrawValuesOnTop(true);
series.setValuesOnTopColor(Color.RED);
//series.setValuesOnTopSize(50);
break;


}
}


}


activity_main.xml:



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="English" >

<requestFocus />
</EditText>

<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hindi" />

<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Physics" />

<EditText
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="social" />

<EditText
android:id="@+id/editText5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Maths" />

<EditText
android:id="@+id/editText6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Biology" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

</LinearLayout>


graph.xml:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.jjoe64.graphview.GraphView
android:layout_width="match_parent"
android:layout_height="200dip"
android:id="@+id/graph" />
</LinearLayout>

0 comments:

Post a Comment