samedi 31 janvier 2015

how to set arraylist value in asynk task to another method


Vote count:

0




I want to set memberlist value which is in asynk task method into onresume method but i am getting null value how i get this value?


this is my code.



public class IndexBar extends Activity implements OnItemClickListener {

HashMap<Character, Integer> alphabetToIndex;
static String TAG = "IndexBar";
int number_of_alphabets = -1;
static IndexBarHandler handler;
private EditText editsearch;
private ArrayAdapter<String> adapter1;
public ArrayAdapter<String> mainadapter;
public ArrayList<String> memberlist;
public ArrayList<String> first;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.indexbarlayout);
editsearch = (EditText) findViewById(R.id.textview_header);
editsearch.addTextChangedListener(new TextWatcher() {


@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
mainadapter.getFilter().filter(s.toString());
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub

}

@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub

}
});
getScreenHeight(this);
getScreenWidth(this);
handler = new IndexBarHandler(this);

}

protected void onResume() {
super.onResume();

/* populating the base listview */
CustomListView mainlistview = (CustomListView) findViewById(R.id.listView_main);
String main_list_array[] = getResources().getStringArray(
R.array.base_array);
if (main_list_array == null) {
Log.d(TAG, "Array of the main listview is null");
return;
}
mainadapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.mainlistview_row/*
* android.R.layout.
* simple_list_item_1
*/,
main_list_array);
mainlistview.setAdapter(mainadapter);
populateHashMap();

}

public int convertDipToPx(int dp, Context context) { // 10dp=15px
Resources r = context.getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
r.getDisplayMetrics());
return (int) px;
}

public int convertPxtoDip(int pixel) { // 15px=23dp
float scale = getResources().getDisplayMetrics().density;
int dips = (int) ((pixel / scale) + 0.5f);
return dips;
}

/**
* Determines the width of the screen in pixels
*
* @return width
*/
public int getScreenWidth(Activity activity) {
Display display = activity.getWindowManager().getDefaultDisplay();
int width = display.getWidth();
Log.d(TAG, "Screen Width in pixels=" + width);
return width;
}

/**
* Determines the height of the screen in pixels
*
* @return height
*/
public int getScreenHeight(Activity activity) {
Display display = activity.getWindowManager().getDefaultDisplay();
int height = display.getHeight();
Log.d(TAG, "Screen Height in pixels=" + height);
return height;
}

public float pixelsToSp(Context context, Float px) {
float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
Log.d(TAG, "GetTextSize in pixels=" + px + " In Sp="
+ (px / scaledDensity));
return px / scaledDensity;
}

public void onItemClick(AdapterView<?> arg0, View view, int arg2, long arg3) {

if (!(view instanceof TextView || view == null))
return;
TextView rowview = (TextView) view;

CharSequence alpahbet = rowview.getText();

if (alpahbet == null || alpahbet.equals(""))
return;

String selected_alpahbet = alpahbet.toString().trim();
Integer position = alphabetToIndex.get(selected_alpahbet.charAt(0));
Log.d(TAG, "Selected Alphabet is:" + selected_alpahbet
+ " position is:" + position);

ListView listview = (ListView) findViewById(R.id.listView_main);
listview.setSelection(position);
}

/**
* This populates the HashMap which contains the mapping between the
* alphabets and their relative position index.
*/
private void populateHashMap() {
alphabetToIndex = new HashMap<Character, Integer>();
String base_list[] = getResources().getStringArray(R.array.base_array);
int base_list_length = base_list.length;

for (int i = 0; i < base_list_length; i++) {
char firstCharacter = base_list[i].charAt(0);
boolean presentOrNot = alphabetToIndex.containsKey(firstCharacter);
if (!presentOrNot) {
alphabetToIndex.put(firstCharacter, i);
// Log.d(TAG,"Character="+firstCharacter+" position="+i);
}
}
number_of_alphabets = alphabetToIndex.size(); // Number of enteries in
// the map is equal to
// number of letters
// that would
// necessarily display
// on the right.

/*
* Now I am making an entry of those alphabets which are not there in
* the Map
*/
String alphabets[] = getResources().getStringArray(
R.array.alphabtes_array);
int index = -1;

for (String alpha1 : alphabets) {
char alpha = alpha1.charAt(0);
index++;

if (alphabetToIndex.containsKey(alpha))
continue;

/*
* Start searching the next character position. Example, here alpha
* is E. Since there is no entry for E, we need to find the position
* of next Character, F.
*/
for (int i = index + 1; i < 26; i++) { // start from next character
// to last character
char searchAlphabet = alphabets[i].charAt(0);

/*
* If we find the position of F character, then on click event
* on E should take the user to F
*/
if (alphabetToIndex.containsKey(searchAlphabet)) {
alphabetToIndex.put(alpha,
alphabetToIndex.get(searchAlphabet));
break;
} else if (i == 25) /*
* If there are no entries after E, then on
* click event on E should take the user to
* end of the list
*/
alphabetToIndex.put(alpha, base_list_length - 1);
else
continue;

}//
}//
}
public void getAllMember() {

new AsyncTask<Void, Void, String>() {
ProgressDialog mProgressDialog;
CustomListView mainlistview = (CustomListView) findViewById(R.id.listView_main);
public String firstname;

protected void onPostExecute(String result) {
mProgressDialog.dismiss();
memberlist = new ArrayList<String>();
first = new ArrayList<String>();

try {
JSONObject jsob = new JSONObject(result.toString());
if (jsob.getString("msg").equalsIgnoreCase("Success")) {
JSONArray datajson = jsob.getJSONArray("data");
for (int i = 0; i < datajson.length(); i++) {

JSONObject c = datajson.getJSONObject(i);
String id = c.getString("iMember_id");
firstname = c.getString("vUsername");
Log.d("firstname val", firstname);

memberlist.add(firstname);

}
mainadapter = new ArrayAdapter<String>(
getBaseContext(),
R.layout.mainlistview_row/*
* android.R.layout.
* simple_list_item_1
*/, memberlist);
mainlistview.setAdapter(mainadapter);

} else {
System.out.println("not a valid user");
}

} catch (Exception e) {
Log.e("login problem", "" + e);

}

}

private void startActivity(Intent i) {
// TODO Auto-generated method stub

}

@Override
protected String doInBackground(Void... arg0) {
// Creating service handler class instance
try {
HttpPost httppost1 = null;
HttpClient httpclient1 = new DefaultHttpClient();

httppost1 = new HttpPost(JsonKey.MAIN_URL);

// Add your data
List<NameValuePair> nameValuePairs1 = new ArrayList<NameValuePair>(
1);
nameValuePairs1.add(new BasicNameValuePair("action",
"GetAllMembers"));
httppost1.setEntity(new UrlEncodedFormEntity(
nameValuePairs1));
// Execute HTTP Post Request
HttpResponse response1 = httpclient1.execute(httppost1);
BufferedReader in1 = new BufferedReader(
new InputStreamReader(response1.getEntity()
.getContent()));
StringBuffer sb1 = new StringBuffer("");
String line1 = "";
while ((line1 = in1.readLine()) != null) {
sb1.append(line1);
}
in1.close();
Log.e(" Get All magazine original data", sb1.toString());
return sb1.toString();
} catch (Exception e) {
Log.e("Get All magazine response problem", "" + e);
return " ";
}
}

@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
mProgressDialog = new ProgressDialog(IndexBar.this);
mProgressDialog.setTitle("");
mProgressDialog.setCanceledOnTouchOutside(false);
mProgressDialog.setMessage("Please Wait...");
mProgressDialog.show();

}
}.execute();

}


}
the value of memberlist in getallmember is i want to set in
mainadapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.mainlistview_row/*
* android.R.layout.
* simple_list_item_1
*/,
main_list_array);


in above code in place of main_array_list but doing so i am getting null pointer exception how i get this value?



asked 31 secs ago







how to set arraylist value in asynk task to another method

How to use function in Where-Object


Vote count:

0




I want filter a list of objects by property "innerText". But I need to do some preparations. Why furhter code doesn't works? It returns all objects.



function enc[[string]$inp]
{
return [System.Text.Encoding]::GetEncoding("windows-1251").GetString([System.Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes($inp))
}

$req.Links | Where-Object { enc($_.innerText) -eq "my string"} | fl


What I'm doing wrong? Unfortunately I didn't find the necessary article in the Internet. There are a lot of such examples: ($_.Name -eq "name") - and nothing valueable for me.



asked 58 secs ago







How to use function in Where-Object

Read hidden field values from another page


Vote count:

0




I am developing a website using ASP.net.


In my home page I have 14 tree view controls. They were placed under Jquery tabs. So when a user click a tab it only appears one treeview. So in tree node changed event currently what I am doing is passing the values from query string to another page. this query string doesnt have any sensitive data. I have to pass what is the selected Tab Id and selected tree node Id.



Response.Redirect(String.Format("~/Display.aspx?tab=1&type={0}",treeview1.SelectedValue), true);


But you know URL is ugly. I dont want to use Friendly URL thing now. So what I did was I put 2 hidden fields values in my home page and I set them when I click the tree node.


So then from the source page I used this code to acess this.



if(Page.PreviousPage!=null)
{
string tab= Page.PreviousPage.FindControl("hftab").UniqueID;
string Type= Page.PreviousPage.FindControl("hfType").UniqueID;
}


But Page.PreviousPage always return NULL. So how to solve this probelem without using sessions and query string. I just want to pass two non sensitive data behind the scenes.



asked 1 min ago

Sylar

114






Read hidden field values from another page

What known interface should inherit that has abstract method for CRUD methods like SelectMethod?


Vote count:

0




I don't know if this concept exist in .NET so I'll describe what I want.


For ObjectDataSource currently we have to tell the Grid controls (.NET DataGrid or Telerik RadGrid) to use which method for SelectMethod, InsertMethod, UpdateMethod, DeleteMethod.


Let's face I have four methods M1, M2, M3, M4 that does all of above actions for ObjectDataSource CRUD operations.


The question is, is there a object or interface that grids know them ? that has abstract method for CRUD operations so I can inherit from it to implement CRUD operations ?


I'm doing this to stop grid controls ask me what method does the InsertMethod and other CRUD operations each time for each object.


Ex interface



interface AutoCRUD {
public abstract void SelectMethod();
public abstract void InsertMethod();
public abstract void UpdateMethod();
public abstract void JDeleteMethod();

}

class Player : AutoCRUD{
CRUD implementions ...
}


Now when I assign Player object to my ObjectDataSource then nothing should appear that ask me which method does UpdateMethod operations. In other words the grid should find out which methods to use by automatically.



asked 1 min ago

Mahdi

1,414






What known interface should inherit that has abstract method for CRUD methods like SelectMethod?

octave ode45 'events' error


Vote count:

0




I am running code in Octave that uses the odepkg 0.8.4. The first .m file called 'poin2.m' is used for getting a Poincare plot. The ode45 command in this file calls the 'spp.m' function.



clc;clear;
OMEG=1.02;
trans=2000;
N=2000;
xfin=zeros(N+1,2);
options=odeset('RelTol',1e-9,'AbsTol',1e-9,'events','on');
xin=0.2;
xdin=-0.2;
for i=1:trans
if rem(i,50)==0
disp(i);
end
[t,x,te,xe,ie]=ode45('spp',[0 2*pi/OMEG],[xin xdin],options);
xin=x(end,1);
xdin=x(end,2);
end
xfin(1,1)=xin;
xfin(1,2)=xdin;
disp('Steady state starts');
for i=1:N
if rem(i,50)==0
disp(i);
end
[t,x,te,xe,ie]=ode45('spp',[0 2*pi/OMEG],[xin xdin],options);

xin=x(end,1);
xdin=x(end,2);
xfin(i+1,1)=x(end,1);
xfin(i+1,2)=x(end,2);
end


The function 'spp.m' contains the piecewise linear ODE to be integrated along with the required 'events' function.



function [xdot,isterminal,dircn]=spp(t,x,flag)
omega=1.02;
alpha=-0.01;q0=0.01;zhi=0.07;epsilon1=0.7;epsilon2=0.005;%epsilon2=0;temp=1;
if nargin<3 || isempty(flag)
if x(1)>1
fh=x(1)-(1-alpha);
elseif x(1)<-1
fh=x(1)+(1-alpha);
else
fh=alpha*x(1);
end
xdot=[x(2);-2*zhi*x(2)-(1+2*epsilon2*cos(omega*t))*fh+q0+(omega^2)*epsilon1*cos(omega*t);];
else
switch flag
case 'events'
xdot=x(1)^2-1;
isterminal=0;
dircn=0;
otherwise
error('function not programmed');
end;
end;


The code runs well in MATLAB but in Octave the following error shows up:



error: Unknown parameter name "events"
error: called from:
error: C:\Software\Octave-3.6.4\share\octave\packages\odepkg-0.8.4\odepkg_stru
cture_check.m at line 308, column 11
error: C:\Software\Octave-3.6.4\share\octave\packages\odepkg-0.8.4\odeset.m at
line 104, column 10
error: C:\Software\Octave-3.6.4\share\octave\packages\odepkg-0.8.4\poin2.m at
line 12, column 8


Line 12 in 'poin2.m' is actually Line 6 in the first code that is posted. I have searched a lot for this problem in 'events' but did not find a solution. Can someone help me out?



asked 57 secs ago







octave ode45 'events' error

Javascript GET not working how do i do it


Vote count:

0




So am trying to do this html code with javascript and php but its not working...


I checked the network tab via firefox i don't see the php code getting through can someone please tell me how i can do this?


I have been trying to do it since yesterday never got it working


Thanks alot



<?php
/**
* Created by PhpStorm.
* User: Joker
* Date: 1/29/2015
* Time: 11:50 PM
*/

ob_implicit_flush(true);
ob_end_flush();
ini_set('max_execution_time', 0);

$start_range = stripslashes($_GET['start_range']);

if (isset($_GET['start_range'])) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/charview.asp?temp={$start_range}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
preg_match('/<title>(.*)<\/title>/siU', $result, $titleMatches);
$title = preg_replace('/\s+/', ' ', $titleMatches[1]);
$title = trim($title);

if (strcmp($title, 'Object moved')) {
echo $title, '</br>';
}
}


?>

<body>
<div style="text-align: center;">
<form>
<input type="text" id="start_range"></br>
<input type="text" id="end_range"></br>
<button onclick="grab_users()">Grab Test</button>
</form>
</div>

<script>
function grab_users() {
var response = '';

var start_id = document.getElementById('start_range');
start_id = start_id.value;
alert(start_id)

$.ajax({ type: "GET",
url: "php/extract.php",
data: {'start_range': start_id},
success : function(text)
{
response = text;
}
});
alert(response);
}
</script>

</body>


asked 1 min ago







Javascript GET not working how do i do it

java.lang.StringIndexOutOfBoundsException: String index out of range: 11


Vote count:

0




I have write the below code for print any type of file but it is giving error String index out of range: 11 is there any problem with the code.


package PrintFile;



import javax.print.*;
import javax.print.attribute.*;
import java.io.*;

public class Printing {

public Printing(String path)
{
file = new File(path);
}

public static void Print() throws Exception
{
//String filename = (Path); // THIS IS THE FILE I WANT TO PRINT
//file = new File(path);

PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; // MY FILE IS .txt TYPE
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);

if (service != null)
{
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(file);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
Thread.sleep(10000);
}
System.exit(0);
}

private File file;

}


asked 49 secs ago







java.lang.StringIndexOutOfBoundsException: String index out of range: 11